File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,14 @@ def perform(*args)
1111 new_word_count = document . computed_word_count
1212 document . update ( cached_word_count : new_word_count )
1313
14+ # Save a WordCountUpdate for this document for today
15+ update = document . word_count_updates . find_or_initialize_by (
16+ for_date : DateTime . current ,
17+ )
18+ update . word_count = new_word_count
19+ update . user_id ||= document . user_id
20+ update . save!
21+
1422 # Make sure we're only storing revisions at least every 5 min
1523 latest_revision = document . document_revisions . order ( 'created_at DESC' ) . limit ( 1 ) . first
1624 if latest_revision . present? && latest_revision . created_at > 5 . minutes . ago
Original file line number Diff line number Diff line change @@ -26,6 +26,12 @@ class Document < ApplicationRecord
2626
2727 attr_accessor :tagged_text
2828
29+ # Duplicated from is_content_page since we don't include that here yet
30+ has_many :word_count_updates , as : :entity , dependent : :destroy
31+ def latest_word_count_cache
32+ word_count_updates . order ( 'for_date DESC' ) . limit ( 1 ) . first . try ( :word_count ) || 0
33+ end
34+
2935 KEYS_TO_TRIGGER_REVISION_ON_CHANGE = %w( title body synopsis notes_text )
3036
3137 def self . color
You can’t perform that action at this time.
0 commit comments