Add db_size attribute in doc manifest

pull/165/head
Thibaut 10 years ago
parent 456c4cb811
commit a59ef1cdb6

@ -1,5 +1,5 @@
class app.models.Doc extends app.Model
# Attributes: name, slug, type, version, index_path, db_path, mtime
# Attributes: name, slug, type, version, index_path, db_path, db_size, mtime
constructor: ->
super

@ -16,6 +16,7 @@ module Docs
def as_json
indexed_docs.map(&:as_json).each do |json|
json[:mtime] = doc_mtime(json)
json[:db_size] = doc_db_size(json)
end
end
@ -34,5 +35,9 @@ module Docs
def doc_mtime(doc)
[@store.mtime(doc[:index_path]).to_i, @store.mtime(doc[:db_path]).to_i].max
end
def doc_db_size(doc)
@store.size(doc[:db_path])
end
end
end

@ -78,6 +78,11 @@ class ManifestTest < MiniTest::Spec
mtime_index, mtime_db = mtime_db, mtime_index
assert_equal mtime_db.to_i, manifest.as_json.first[:mtime]
end
it "adds a :db_size attribute" do
stub(store).size(db_path) { 42 }
assert_equal 42, manifest.as_json.first[:db_size]
end
end
context "when the doc doesn't have an index" do

Loading…
Cancel
Save