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)
11
11
new_word_count = document . computed_word_count
12
12
document . update ( cached_word_count : new_word_count )
13
13
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
+
14
22
# Make sure we're only storing revisions at least every 5 min
15
23
latest_revision = document . document_revisions . order ( 'created_at DESC' ) . limit ( 1 ) . first
16
24
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
26
26
27
27
attr_accessor :tagged_text
28
28
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
+
29
35
KEYS_TO_TRIGGER_REVISION_ON_CHANGE = %w( title body synopsis notes_text )
30
36
31
37
def self . color
You can’t perform that action at this time.
0 commit comments