Use count instead of action
In order to be able to combine multiple log entries (and of different types) into one, we now set the object count instead of an action verb when logging an operation.
This commit is contained in:
parent
61478d8c8c
commit
95f24beef7
@ -106,8 +106,8 @@ module RemoteStorage
|
||||
|
||||
object.store
|
||||
|
||||
log_action = object_exists ? "update" : "create"
|
||||
log_operation(user, directory, log_action, new_object_size, existing_object_size)
|
||||
log_count = object_exists ? 0 : 1
|
||||
log_operation(user, directory, log_count, new_object_size, existing_object_size)
|
||||
|
||||
update_all_directory_objects(user, directory, timestamp)
|
||||
|
||||
@ -127,7 +127,7 @@ module RemoteStorage
|
||||
riak_response = data_bucket.delete("#{user}:#{directory}:#{key}")
|
||||
|
||||
if riak_response[:code] != 404
|
||||
log_operation(user, directory, "delete", 0, existing_object_size)
|
||||
log_operation(user, directory, -1, 0, existing_object_size)
|
||||
end
|
||||
|
||||
timestamp = (Time.now.to_f * 1000).to_i
|
||||
@ -161,11 +161,11 @@ module RemoteStorage
|
||||
object
|
||||
end
|
||||
|
||||
def log_operation(user, directory, action, new_size=0, old_size=0)
|
||||
def log_operation(user, directory, count, new_size=0, old_size=0)
|
||||
log_entry = opslog_bucket.new
|
||||
log_entry.content_type = "application/json"
|
||||
log_entry.data = {
|
||||
"action" => action,
|
||||
"count" => count,
|
||||
"size" => (-old_size + new_size),
|
||||
"category" => extract_category(directory)
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ describe "App with Riak backend" do
|
||||
objects = []
|
||||
opslog_bucket.keys.each { |k| objects << opslog_bucket.get(k) rescue nil }
|
||||
|
||||
log_entry = objects.select{|o| o.data["action"] == "create"}.first
|
||||
log_entry = objects.select{|o| o.data["count"] == 1}.first
|
||||
log_entry.data["size"].must_equal 12
|
||||
log_entry.data["category"].must_equal "documents"
|
||||
log_entry.indexes["user_id_bin"].must_include "jimmy"
|
||||
@ -209,12 +209,12 @@ describe "App with Riak backend" do
|
||||
objects = []
|
||||
opslog_bucket.keys.each { |k| objects << opslog_bucket.get(k) rescue nil }
|
||||
|
||||
create_entry = objects.select{|o| o.data["action"] == "create"}.first
|
||||
create_entry = objects.select{|o| o.data["count"] == 1}.first
|
||||
create_entry.data["size"].must_equal 11
|
||||
create_entry.data["category"].must_equal "documents"
|
||||
create_entry.indexes["user_id_bin"].must_include "jimmy"
|
||||
|
||||
update_entry = objects.select{|o| o.data["action"] == "update"}.first
|
||||
update_entry = objects.select{|o| o.data["count"] == 0}.first
|
||||
update_entry.data["size"].must_equal 9
|
||||
update_entry.data["category"].must_equal "documents"
|
||||
update_entry.indexes["user_id_bin"].must_include "jimmy"
|
||||
@ -235,7 +235,7 @@ describe "App with Riak backend" do
|
||||
objects = []
|
||||
opslog_bucket.keys.each { |k| objects << opslog_bucket.get(k) rescue nil }
|
||||
|
||||
log_entry = objects.select{|o| o.data["action"] == "create"}.first
|
||||
log_entry = objects.select{|o| o.data["count"] == 1}.first
|
||||
log_entry.data["size"].must_equal 12
|
||||
log_entry.data["category"].must_equal "public/documents"
|
||||
log_entry.indexes["user_id_bin"].must_include "jimmy"
|
||||
@ -277,7 +277,7 @@ describe "App with Riak backend" do
|
||||
objects = []
|
||||
opslog_bucket.keys.each { |k| objects << opslog_bucket.get(k) rescue nil }
|
||||
|
||||
log_entry = objects.select{|o| o.data["action"] == "create"}.first
|
||||
log_entry = objects.select{|o| o.data["count"] == 1}.first
|
||||
log_entry.data["size"].must_equal 16044
|
||||
log_entry.data["category"].must_equal "documents"
|
||||
log_entry.indexes["user_id_bin"].must_include "jimmy"
|
||||
@ -373,7 +373,7 @@ describe "App with Riak backend" do
|
||||
objects = []
|
||||
opslog_bucket.keys.each { |k| objects << opslog_bucket.get(k) rescue nil }
|
||||
|
||||
log_entry = objects.select{|o| o.data["action"] == "delete"}.first
|
||||
log_entry = objects.select{|o| o.data["count"] == -1}.first
|
||||
log_entry.data["size"].must_equal(-22)
|
||||
log_entry.data["category"].must_equal "documents"
|
||||
log_entry.indexes["user_id_bin"].must_include "jimmy"
|
||||
@ -387,7 +387,7 @@ describe "App with Riak backend" do
|
||||
it "doesn't log the operation" do
|
||||
objects = []
|
||||
opslog_bucket.keys.each { |k| objects << opslog_bucket.get(k) rescue nil }
|
||||
objects.select{|o| o.data["action"] == "delete"}.size.must_equal 1
|
||||
objects.select{|o| o.data["count"] == -1}.size.must_equal 1
|
||||
end
|
||||
end
|
||||
|
||||
@ -419,7 +419,7 @@ describe "App with Riak backend" do
|
||||
objects = []
|
||||
opslog_bucket.keys.each { |k| objects << opslog_bucket.get(k) rescue nil }
|
||||
|
||||
log_entry = objects.select{|o| o.data["action"] == "delete" && o.data["size"] == -16044}.first
|
||||
log_entry = objects.select{|o| o.data["count"] == -1 && o.data["size"] == -16044}.first
|
||||
log_entry.data["category"].must_equal "documents"
|
||||
log_entry.indexes["user_id_bin"].must_include "jimmy"
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user