Ruby 我可以在处理输入之前重定向吗?
我目前拥有的是:Ruby 我可以在处理输入之前重定向吗?,ruby,redirect,optimization,sinatra,Ruby,Redirect,Optimization,Sinatra,我目前拥有的是: get "/" do submitMeToTheDatabase = veryLongFunction(params[:processme]) Information.create(complicatedInformation:submitMeToTheDatabase) redirect "/otherPage" end 如果我这样做的话,它会以同样的方式工作,但会改进用户的加载时间吗 get "/" do redirect "/otherP
get "/" do
submitMeToTheDatabase = veryLongFunction(params[:processme])
Information.create(complicatedInformation:submitMeToTheDatabase)
redirect "/otherPage"
end
如果我这样做的话,它会以同样的方式工作,但会改进用户的加载时间吗
get "/" do
redirect "/otherPage"
submitMeToTheDatabase = veryLongFunction(params[:processme])
Information.create(complicatedInformation:submitMeToTheDatabase)
end
附录
完成同样事情的另一种方法是什么?大致如下:
get "/" do
fork do
submitMeToTheDatabase = veryLongFunction(params[:processme])
Information.create(complicatedInformation:submitMeToTheDatabase)
end
redirect "/otherPage"
end
我已经有一段时间没有使用sinatra了,但我认为第二种方法行不通
redirect
方法的显示redirect
调用halt()并立即停止任何进一步的处理
您可以将任务放到作业队列中,并在另一个线程上处理它。看看能不能理解我的意思
queue = Queue.new
get "/" do
queue << params[:processme]
redirect "/otherPage"
end
consumer = Thread.new do
loop do
data = queue.pop
submitMe = veryLongFunction(data)
Information.create(complicatedInformation:submitMeToTheDatabase)
end
end
queue=queue.new
得到“/”做
将复杂的信息排队:提交到数据库
?看起来你编了一些示例代码,但这甚至不是有效的语法。@马特,对不起,这是activerecord语法,我只是编了一些需要很长时间才能处理的东西啊,对了,这是哈希语法。没有空格看起来有点不寻常,但它是有效的。