mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
cache word counts on revisions + polish
This commit is contained in:
parent
05660ee8b1
commit
4352545656
@ -8,7 +8,8 @@ class SaveDocumentRevisionJob < ApplicationJob
|
||||
return unless document.present?
|
||||
|
||||
# Update cached word count for the document regardless of how often this is called
|
||||
document.update(cached_word_count: document.computed_word_count)
|
||||
new_word_count = document.computed_word_count
|
||||
document.update(cached_word_count: new_word_count)
|
||||
|
||||
# Make sure we're only storing revisions at least every 5 min
|
||||
latest_revision = document.document_revisions.order('created_at DESC').limit(1).first
|
||||
@ -18,11 +19,12 @@ class SaveDocumentRevisionJob < ApplicationJob
|
||||
|
||||
# Store the document information as-is
|
||||
document.document_revisions.create!(
|
||||
title: document.title,
|
||||
body: document.body,
|
||||
synopsis: document.synopsis,
|
||||
universe_id: document.universe_id,
|
||||
notes_text: document.notes_text
|
||||
title: document.title,
|
||||
body: document.body,
|
||||
synopsis: document.synopsis,
|
||||
universe_id: document.universe_id,
|
||||
notes_text: document.notes_text,
|
||||
cached_word_count: new_word_count
|
||||
)
|
||||
end
|
||||
end
|
||||
@ -108,7 +108,8 @@
|
||||
},
|
||||
title: "Last 45 days",
|
||||
ytitle: "minutes",
|
||||
colors: [Document.color]
|
||||
colors: [Document.color],
|
||||
suffix: " minutes"
|
||||
%>
|
||||
<br />
|
||||
<%=
|
||||
@ -117,7 +118,8 @@
|
||||
},
|
||||
title: "All time",
|
||||
ytitle: "minutes",
|
||||
colors: [Document.color]
|
||||
colors: [Document.color],
|
||||
suffix: " minutes"
|
||||
%>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
class AddCachedWordCountToDocumentRevisions < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :document_revisions, :cached_word_count, :integer
|
||||
end
|
||||
end
|
||||
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2021_07_01_002938) do
|
||||
ActiveRecord::Schema.define(version: 2021_07_02_054655) do
|
||||
|
||||
create_table "active_storage_attachments", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
@ -1174,6 +1174,7 @@ ActiveRecord::Schema.define(version: 2021_07_01_002938) do
|
||||
t.datetime "deleted_at"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.integer "cached_word_count"
|
||||
t.index ["document_id"], name: "index_document_revisions_on_document_id"
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user