Skip to content

Commit

Permalink
[sphinx] Rake task openshift:thinking_sphinx:start
Browse files Browse the repository at this point in the history
It does not create a thread for indexing anymore

All indexing is done real time in background with Sidekiq

To initialize an indexation, run `rake ts:rt:index`
  • Loading branch information
hallelujah committed Jun 22, 2020
1 parent a506172 commit 4b01db2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 49 deletions.
14 changes: 4 additions & 10 deletions app/indices/account_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
has :tenant_id, type: :integer
has :state, type: :string

# if System::Database.oracle?
# # Need to add the group by otherwise it will complain about ORA-00979 not a Group By function error
# group_by "accounts.state"
# end

# where sanitize_sql(['COALESCE(accounts.master, ?) = ?', false, false])
scope { Account.where(master: false).includes(:users, :bought_cinstances) }
end

module AccountIndex
Expand All @@ -41,13 +36,11 @@ def sphinx_usernames
end

def sphinx_full_names
users.select(:first_name, :last_name)
.pluck(:first_name, :last_name)
.flatten.join(' ')
users.pluck(:first_name, :last_name).flatten.join(' ')
end

def sphinx_emails
users.select(:email).pluck(:email).join(' ')
users.pluck(:email).join(' ')
end

def sphinx_user_keys
Expand Down Expand Up @@ -89,6 +82,7 @@ def account_for_sphinx

def index_account
return unless account_for_sphinx&.persisted?

SphinxIndexationWorker.perform_later(account_for_sphinx)
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/indices/cms_page_index.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# frozen_string_literal: true

ThinkingSphinx::Index.define 'cms/page', with: :real_time do
indexes :title
has :tenant_id, type: :integer

indexes :published
scope { CMS::Page.where(searchable: true) }
end

module CMSPageIndex
Expand All @@ -16,6 +19,7 @@ module CMSPageIndex

def sphinx_index
return unless searchable?

SphinxIndexationWorker.perform_later(self)
end
end
4 changes: 4 additions & 0 deletions app/indices/topic_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
has :forum_id, type: :integer
has :sticky, type: :boolean
has :last_updated_at, type: :timestamp

scope { Topic.includes(:posts) }
end
end

Expand All @@ -36,6 +38,7 @@ module ForPost

def index_topic
return if System::Database.oracle?

SphinxIndexationWorker.perform_later(topic)
end
end
Expand All @@ -44,6 +47,7 @@ def index_topic

def sphinx_index
return if System::Database.oracle?

SphinxIndexationWorker.perform_later(self)
end
end
39 changes: 0 additions & 39 deletions lib/tasks/openshift.rake
Original file line number Diff line number Diff line change
Expand Up @@ -41,47 +41,8 @@ ERROR_MESSAGE
daemon.stop
interface.configure

require 'thread'
queue = Queue.new

Thread.abort_on_exception = true

reindex_interval = Integer(ENV['FULL_REINDEX_INTERVAL'] || '24').hours
reindex_thread = Thread.new do
loop do
warn 'Index starting'
queue << interface.sql.index(false)
warn 'Index finished'
sleep reindex_interval
end
end

queue.pop # wait for first full index

delta_interval = Integer(ENV['DELTA_INDEX_INTERVAL'] || '60').minutes
delta_thread = Thread.new do

loop do
warn 'Delta index starting'
queue << ThinkingSphinx::Deltas::DatetimeDelta.index
warn 'Delta index finished'
sleep delta_interval
end
end

queue.pop # wait for first delta index

daemon.start
at_exit { daemon.stop }

begin
delta_thread.join
reindex_thread.join
rescue Interrupt, SignalException
delta_thread.kill
reindex_thread.kill
daemon.stop
end
end
end

Expand Down

0 comments on commit 4b01db2

Please sign in to comment.