Add user id index to usage size keys

This commit is contained in:
Basti 2013-04-21 17:48:21 +02:00
parent 45d44bbf26
commit 1a9be076fa
2 changed files with 6 additions and 2 deletions

View File

@ -156,12 +156,13 @@ module RemoteStorage
def log_object_size(user, directory, new_size=0, old_size=0)
category = extract_category(directory)
info = info_bucket.get_or_new("usage:size:#{user}:#{category}")
info.content_type = "text/plain"
size = -old_size + new_size
size += info.data.to_i
info.data = size.to_s
info.indexes.merge!({:user_id_bin => [user]})
info.store
end

View File

@ -111,8 +111,11 @@ describe "App with Riak backend" do
data_bucket.get("jimmy:documents:bar").content_type.must_equal "text/plain; charset=utf-8"
end
it "increases the overall category size" do
it "increases the usage size counter" do
info_bucket.get("usage:size:jimmy:documents").data.must_equal "35"
indexes = info_bucket.get("usage:size:jimmy:documents").indexes
indexes["user_id_bin"].must_include "jimmy"
end
it "indexes the data set" do