-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8121 from alphagov/delete-search-index-records-wh…
…en-edition-becomes-unindexable Delete search index records when an edition becomes unindexable
- Loading branch information
Showing
3 changed files
with
24 additions
and
0 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
9 changes: 9 additions & 0 deletions
9
db/data_migration/20230816152924_remove_orphaned_edition_search_index_records.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,9 @@ | ||
class RemoveOrphanedEditionSearchIndexRecords < ActiveRecord::Migration[7.0] | ||
def change | ||
# We want to find all editions which are publicly visible and therefore might once have been indexed, but are currently not searchable | ||
# We then ask Search API to remove the record for these editions if a corresponding record is present | ||
# Note that this doesn't seem to capture all foreign language content in the search index, but it has removed at least some | ||
editions_with_possible_orphaned_search_index_records = Edition.publicly_visible.where.not(id: Edition.search_only.select(:id)) | ||
editions_with_possible_orphaned_search_index_records.each { |e| ServiceListeners::SearchIndexer.new(e).remove! } | ||
end | ||
end |
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