-
Notifications
You must be signed in to change notification settings - Fork 2
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 #247 from lnu-norge/rethinking-filtering-by-facility
Faster search
- Loading branch information
Showing
13 changed files
with
239 additions
and
51 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class AddScoreToSpaceFacility < ActiveRecord::Migration[7.1] | ||
def up | ||
add_column :space_facilities, :score, :integer, default: 0 | ||
|
||
# In a transaction, calculate score for all space facilities | ||
SpaceFacility.transaction do | ||
count = SpaceFacility.count.to_i | ||
SpaceFacility.all.each_with_index do |space_facility, index| | ||
print "\rCalculating score for #{index + 1} / #{count} " | ||
space_facility.calculate_score | ||
end | ||
end | ||
end | ||
|
||
def down | ||
remove_column :space_facilities, :score | ||
end | ||
end |
64 changes: 64 additions & 0 deletions
64
db/migrate/20240926071852_add_counter_caches_to_personal_space_list.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,64 @@ | ||
class AddCounterCachesToPersonalSpaceList < ActiveRecord::Migration[7.1] | ||
def up | ||
add_column :personal_space_lists, :space_count, :integer, default: 0 | ||
add_column :personal_space_lists, :space_not_contacted_count, :integer, default: 0 | ||
add_column :personal_space_lists, :space_said_no_count, :integer, default: 0 | ||
add_column :personal_space_lists, :space_said_maybe_count, :integer, default: 0 | ||
add_column :personal_space_lists, :space_said_yes_count, :integer, default: 0 | ||
|
||
# Update the counter caches | ||
execute <<-SQL | ||
UPDATE personal_space_lists | ||
SET | ||
space_count = ( | ||
SELECT COUNT(*) | ||
FROM personal_space_lists_spaces | ||
WHERE personal_space_lists_spaces.personal_space_list_id = personal_space_lists.id | ||
), | ||
space_not_contacted_count = ( | ||
SELECT COUNT(*) | ||
FROM personal_space_lists_spaces | ||
JOIN personal_data_on_space_in_lists ON | ||
personal_data_on_space_in_lists.space_id = personal_space_lists_spaces.space_id AND | ||
personal_data_on_space_in_lists.personal_space_list_id = personal_space_lists_spaces.personal_space_list_id | ||
WHERE personal_space_lists_spaces.personal_space_list_id = personal_space_lists.id | ||
AND personal_data_on_space_in_lists.contact_status = 0 | ||
), | ||
space_said_no_count = ( | ||
SELECT COUNT(*) | ||
FROM personal_space_lists_spaces | ||
JOIN personal_data_on_space_in_lists ON | ||
personal_data_on_space_in_lists.space_id = personal_space_lists_spaces.space_id AND | ||
personal_data_on_space_in_lists.personal_space_list_id = personal_space_lists_spaces.personal_space_list_id | ||
WHERE personal_space_lists_spaces.personal_space_list_id = personal_space_lists.id | ||
AND personal_data_on_space_in_lists.contact_status = 1 | ||
), | ||
space_said_maybe_count = ( | ||
SELECT COUNT(*) | ||
FROM personal_space_lists_spaces | ||
JOIN personal_data_on_space_in_lists ON | ||
personal_data_on_space_in_lists.space_id = personal_space_lists_spaces.space_id AND | ||
personal_data_on_space_in_lists.personal_space_list_id = personal_space_lists_spaces.personal_space_list_id | ||
WHERE personal_space_lists_spaces.personal_space_list_id = personal_space_lists.id | ||
AND personal_data_on_space_in_lists.contact_status = 2 | ||
), | ||
space_said_yes_count = ( | ||
SELECT COUNT(*) | ||
FROM personal_space_lists_spaces | ||
JOIN personal_data_on_space_in_lists ON | ||
personal_data_on_space_in_lists.space_id = personal_space_lists_spaces.space_id AND | ||
personal_data_on_space_in_lists.personal_space_list_id = personal_space_lists_spaces.personal_space_list_id | ||
WHERE personal_space_lists_spaces.personal_space_list_id = personal_space_lists.id | ||
AND personal_data_on_space_in_lists.contact_status = 3 | ||
) | ||
SQL | ||
end | ||
|
||
def down | ||
remove_column :personal_space_lists, :space_count | ||
remove_column :personal_space_lists, :space_not_contacted_count | ||
remove_column :personal_space_lists, :space_said_no_count | ||
remove_column :personal_space_lists, :space_said_maybe_count | ||
remove_column :personal_space_lists, :space_said_yes_count | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.