Skip to content

Commit a59ef1c

Browse files
committed
Add db_size attribute in doc manifest
1 parent 456c4cb commit a59ef1c

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎assets/javascripts/models/doc.coffee‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class app.models.Doc extends app.Model
2-
# Attributes: name, slug, type, version, index_path, db_path, mtime
2+
# Attributes: name, slug, type, version, index_path, db_path, db_size, mtime
33

44
constructor: ->
55
super

‎lib/docs/core/manifest.rb‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def store
1616
def as_json
1717
indexed_docs.map(&:as_json).each do |json|
1818
json[:mtime] = doc_mtime(json)
19+
json[:db_size] = doc_db_size(json)
1920
end
2021
end
2122

@@ -34,5 +35,9 @@ def indexed_docs
3435
def doc_mtime(doc)
3536
[@store.mtime(doc[:index_path]).to_i, @store.mtime(doc[:db_path]).to_i].max
3637
end
38+
39+
def doc_db_size(doc)
40+
@store.size(doc[:db_path])
41+
end
3742
end
3843
end

‎test/lib/docs/core/manifest_test.rb‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ class ManifestTest < MiniTest::Spec
7878
mtime_index, mtime_db = mtime_db, mtime_index
7979
assert_equal mtime_db.to_i, manifest.as_json.first[:mtime]
8080
end
81+
82+
it "adds a :db_size attribute" do
83+
stub(store).size(db_path) { 42 }
84+
assert_equal 42, manifest.as_json.first[:db_size]
85+
end
8186
end
8287

8388
context "when the doc doesn't have an index" do

0 commit comments

Comments
 (0)