Skip to content

Commit

Permalink
Creates rake task for refreshing the full text materialized view
Browse files Browse the repository at this point in the history
  • Loading branch information
cbothner committed Nov 1, 2017
1 parent 62c54eb commit 85508d3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ When developing the LTI tool provider components of Gala, it is useful to be abl
1. Trust the certificate on your host machine using Keychain Access. Drag `localhost.crt` into the app, then Get Info and choose Always Trust.
1. Start the development servers with `LOCALHOST_SSL=true foreman start`
1. Browse to https://localhost:3000 (http will not work)

## Cron jobs

The full-text case search is powered by a Postgres materialized view so it’s
really fast. The consequence is that changes don’t appear in search results
until the view is refreshed. Set a cron job or use Heroku Scheduler or the
equivalent to run `rake indices:refresh` as frequently as makes sense.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def up
LEFT JOIN cards ON cards.case_id = pages.id
GROUP BY cases.id;
CREATE UNIQUE INDEX index_cases_search_index_en ON cases_search_index_en
USING btree(id);
CREATE INDEX index_cases_on_english_full_text ON cases_search_index_en
USING gin(document);
SQL
Expand All @@ -62,6 +64,7 @@ def up
def down
execute <<~SQL
DROP INDEX index_cases_on_english_full_text;
DROP INDEX index_cases_search_index_en;
DROP MATERIALIZED VIEW cases_search_index_en;
SQL
end
Expand Down
7 changes: 7 additions & 0 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,13 @@ CREATE UNIQUE INDEX index_cases_on_slug ON cases USING btree (slug);
CREATE INDEX index_cases_on_tags ON cases USING gin (tags);


--
-- Name: index_cases_search_index_en; Type: INDEX; Schema: public; Owner: -
--

CREATE UNIQUE INDEX index_cases_search_index_en ON cases_search_index_en USING btree (id);


--
-- Name: index_comment_threads_on_card_id; Type: INDEX; Schema: public; Owner: -
--
Expand Down
10 changes: 10 additions & 0 deletions lib/tasks/indices.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

namespace :indices do
desc 'Refresh the index for full-text searching of cases'
task refresh: :environment do
ActiveRecord::Base.connection.execute <<~SQL
REFRESH MATERIALIZED VIEW CONCURRENTLY cases_search_index_en;
SQL
end
end

0 comments on commit 85508d3

Please sign in to comment.