Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Only reindex necessary gists

  • Loading branch information...
commit e6ddbf4d391c3224abaf1d70eb9d3998367385eb 1 parent 1156e59
Ryan Daigle authored
3  app/controllers/sessions_controller.rb
@@ -14,7 +14,10 @@ def create
14 14 redirect_to(request.env['omniauth.origin'] || search_gists_path)
15 15 else
16 16 log({ns: self.class, fn: __method__, measure: true, at: 'first-login'}, user)
  17 +
  18 + # Need to encapsulate...
17 19 QC.enqueue("GistFetcher.fetch_gists", user.id)
  20 + QC.enqueue("GistFetcher.fetch_starred_gists", user.id)
18 21 QC.enqueue("User.refresh_index", user.id)
19 22 redirect_to status_gists_path
20 23 end
1  app/models/gist.rb
@@ -11,6 +11,7 @@ class Gist < ActiveRecord::Base
11 11 scope :with_ids, lambda { |ids| where(ids.any? ? ["id in (?)", ids] : "1 = 0") }
12 12 scope :starred, where(starred: true)
13 13 scope :not_starred, where(["starred = ? OR starred IS NULL", false])
  14 + scope :since, lambda { |time| time ? where(["updated_at > ?", time]) : scoped }
14 15
15 16 index_name ELASTICSEARCH_INDEX_NAME
16 17
2  app/models/gist_fetcher.rb
@@ -16,6 +16,7 @@ def fetch_gists(user_id)
16 16
17 17 user = User.find(user_id)
18 18 since = user.last_gist_updated_at(user.gists.not_starred)
  19 + since = since ? (since + 1.second) : since
19 20
20 21 gh_client(user) do |gh|
21 22 log({ns: self, fn: __method__, measure: true, since: since}, user) do
@@ -31,6 +32,7 @@ def fetch_starred_gists(user_id)
31 32
32 33 user = User.find(user_id)
33 34 since = user.last_gist_updated_at(user.gists.starred)
  35 + since = since ? (since + 1.second) : since
34 36
35 37 gh_client(user) do |gh|
36 38 log({ns: self, fn: __method__, measure: true, since: since}, user) do
2  app/models/user.rb
@@ -36,7 +36,7 @@ def refresh_indexes
36 36 def refresh_index(user_id)
37 37 user = User.find(user_id)
38 38 log({ns: self, fn: __method__}, user) do
39   - Gist.reindex(user.gists)
  39 + Gist.reindex(user.gists.since(user.last_indexed_at))
40 40 user.indexed!
41 41 end
42 42 end

0 comments on commit e6ddbf4

Please sign in to comment.
Something went wrong with that request. Please try again.