From c088fcf0b5aaf31195ec1b94873e93f1fd3ee8ed Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 10 Oct 2014 16:14:15 -0400 Subject: [PATCH] 3692: Explicitly incorporate sequence number test into where clause --- services/api/lib/eventbus.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/services/api/lib/eventbus.rb b/services/api/lib/eventbus.rb index 9f74b5db84..96e9d04322 100644 --- a/services/api/lib/eventbus.rb +++ b/services/api/lib/eventbus.rb @@ -57,20 +57,24 @@ class EventBus # Start with log rows readable by user, sorted in ascending order logs = Log.readable_by(ws.user).order("id asc") + cond_id = nil + cond_out = [] + param_out = [] + if ws.last_log_id # Client is only interested in log rows that are newer than the # last log row seen by the client. - logs = logs.where("logs.id > ?", ws.last_log_id) + cond_id = "logs.id > ?" + param_out << ws.last_log_id elsif id # No last log id, so only look at the most recently changed row - logs = logs.where("logs.id = ?", id.to_i) + cond_id = "logs.id = ?" + param_out << id.to_i else return end # Now process filters provided by client - cond_out = [] - param_out = [] ws.filters.each do |filter| ft = record_filters filter.filters, Log if ft[:cond_out].any? @@ -81,7 +85,9 @@ class EventBus # Add filters to query if cond_out.any? - logs = logs.where("(#{cond_out.join ') OR ('})", *param_out) + logs = logs.where(cond_id + " AND (#{cond_out.join ') OR ('})", *param_out) + else + logs = logs.where(cond_id, *param_out) end # Finally execute query and actually send the matching log rows -- 2.30.2