-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Speed up admin learner search (#4918)
Because: - The default configuration is not fast enough for the amount of data we have in production. This commit: - Adds a ts_vector column to the users table which we can search against - this is recommended in the [pg_search docs](https://github.com/Casecommons/pg_search?tab=readme-ov-file#using-tsvector-columns) - Sneaks in a data-turbo-action="advance" attribute to the learner search results turbo frame so we can share search result pages with admins if we need to.
- Loading branch information
1 parent
b5788af
commit 403dc98
Showing
4 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
db/migrate/20250212143446_add_search_ts_vector_column_to_users.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class AddSearchTsVectorColumnToUsers < ActiveRecord::Migration[7.1] | ||
disable_ddl_transaction! | ||
|
||
def change | ||
execute <<-SQL.squish | ||
ALTER TABLE users | ||
ADD COLUMN search_tsvector tsvector GENERATED ALWAYS AS ( | ||
setweight(to_tsvector('english', coalesce(email, '')), 'A') || | ||
setweight(to_tsvector('english', coalesce(username,'')), 'B') | ||
) STORED; | ||
SQL | ||
|
||
add_index :users, :search_tsvector, using: :gin, algorithm: :concurrently | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.