Skip to content

Commit

Permalink
Back out the counter cache
Browse files Browse the repository at this point in the history
It caused other issues like in tests, and I'm not sure it was a slam dunk.
  • Loading branch information
epugh committed Jan 8, 2025
1 parent 6164b1e commit fd8f0f8
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 28 deletions.
11 changes: 10 additions & 1 deletion app/models/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# import_job :string(255)
# name :string(255)
# populate_job :string(255)
# query_doc_pairs_count :integer default(0), not null
# show_rank :boolean default(FALSE)
# support_implicit_judgements :boolean
# created_at :datetime not null
Expand Down Expand Up @@ -65,6 +64,16 @@ class Book < ApplicationRecord

# Scopes
include ForUserScope

scope :with_counts, -> {
select <<~SQL.squish
books.*,
(
SELECT COUNT(query_doc_pairs.id) FROM query_doc_pairs
WHERE book_id = books.id
) AS query_doc_pairs_count
SQL
}

private

Expand Down
2 changes: 1 addition & 1 deletion app/models/query_doc_pair.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# fk_rails_... (book_id => books.id)
#
class QueryDocPair < ApplicationRecord
belongs_to :book, counter_cache: true
belongs_to :book
has_many :judgements, dependent: :destroy, autosave: true

validates :query_text, presence: true, length: { maximum: 2048 }
Expand Down

This file was deleted.

17 changes: 0 additions & 17 deletions db/migrate/20241218173819_reset_all_book_cache_counters.rb

This file was deleted.

3 changes: 1 addition & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion test/fixtures/books.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# import_job :string(255)
# name :string(255)
# populate_job :string(255)
# query_doc_pairs_count :integer default(0), not null
# show_rank :boolean default(FALSE)
# support_implicit_judgements :boolean
# created_at :datetime not null
Expand Down
1 change: 0 additions & 1 deletion test/models/book_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# import_job :string(255)
# name :string(255)
# populate_job :string(255)
# query_doc_pairs_count :integer default(0), not null
# show_rank :boolean default(FALSE)
# support_implicit_judgements :boolean
# created_at :datetime not null
Expand Down

0 comments on commit fd8f0f8

Please sign in to comment.