diff --git a/lib/remote_storage/riak.rb b/lib/remote_storage/riak.rb index ac8f927..f812134 100644 --- a/lib/remote_storage/riak.rb +++ b/lib/remote_storage/riak.rb @@ -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 diff --git a/spec/riak_spec.rb b/spec/riak_spec.rb index d9324bf..f43dcf4 100644 --- a/spec/riak_spec.rb +++ b/spec/riak_spec.rb @@ -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