add a timeout to long-running last queries
This commit is contained in:
parent
0cc4e1b540
commit
ae9000572b
@ -161,12 +161,20 @@ class FeedController < ApplicationController
|
|||||||
|
|
||||||
# if last entry
|
# if last entry
|
||||||
if params[:id] == 'last' && params[:field_id].present? && params[:field_id].to_i != 0
|
if params[:id] == 'last' && params[:field_id].present? && params[:field_id].to_i != 0
|
||||||
# look for a feed where the value isn't null
|
begin
|
||||||
@feed = Feed.where(:channel_id => @channel.id)
|
# add a timeout since this query may be really long if there is a lot of data,
|
||||||
.where("field? is not null", params[:field_id].to_i)
|
# but the last instance of the field is very far back
|
||||||
.select(Feed.select_options(@channel, params))
|
Timeout::timeout(5) do
|
||||||
.order('entry_id desc')
|
# look for a feed where the value isn't null
|
||||||
.first
|
@feed = Feed.where(:channel_id => @channel.id)
|
||||||
|
.where("field? is not null", params[:field_id].to_i)
|
||||||
|
.select(Feed.select_options(@channel, params))
|
||||||
|
.order('entry_id desc')
|
||||||
|
.first
|
||||||
|
end
|
||||||
|
rescue Timeout::Error
|
||||||
|
rescue
|
||||||
|
end
|
||||||
# else get by entry
|
# else get by entry
|
||||||
else
|
else
|
||||||
# get most recent entry if necessary
|
# get most recent entry if necessary
|
||||||
|
Loading…
Reference in New Issue
Block a user