Skip to content

Commit

Permalink
Limit seek to greedy search by 2 partition periods
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmetal committed Mar 27, 2018
1 parent b9c65c4 commit 38f42ad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ gem 'chronic'
gem 'kubeclient'

gem 'pry', group: :development
gem 'dotenv', require: 'dotenv/load', group: :development
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GEM
concurrent-ruby (1.0.5)
domain_name (0.5.20161021)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.2.1)
erubis (2.7.0)
faraday (0.14.0)
multipart-post (>= 1.2, < 3)
Expand Down Expand Up @@ -103,6 +104,7 @@ DEPENDENCIES
activesupport
chronic
clickhouse!
dotenv
json
kubeclient
parslet
Expand Down
10 changes: 8 additions & 2 deletions lib/loghouse_query/clickhouse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ def result_newer(start_time, lim, stop_at = nil)
def result_from_seek_to
lim = limit || Pagination::DEFAULT_PER_PAGE

seek_to_max_periods = 2

max_search_before = parsed_seek_to - (LogsTables::PARTITION_PERIOD.hours * seek_to_max_periods)
max_search_after = parsed_seek_to + (LogsTables::PARTITION_PERIOD.hours * seek_to_max_periods)
max_search_after = Time.zone.now if max_search_after > Time.zone.now

# search before part
before = result_older(parsed_seek_to, lim)
before = result_older(parsed_seek_to, lim, max_search_before)

# search after part
after = result_newer(parsed_seek_to, lim, Time.zone.now)
after = result_newer(parsed_seek_to, lim, max_search_after)

res = after.last([before.count, lim / 2].min)
res += before.first(lim - res.count)
Expand Down

0 comments on commit 38f42ad

Please sign in to comment.