-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
96 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,29 @@ | ||
local hash_values_array = cjson.decode(redis.call('get', (KEYS[1]))) | ||
redis.call('DEL', KEYS[1]) | ||
for i, hash_values in ipairs(hash_values_array) do | ||
local function remove(key) | ||
local val = hash_values[key] | ||
hash_values[key] = nil | ||
return val | ||
local hmset = function (key, dict) | ||
if next(dict) == nil then return nil end | ||
local bulk = {} | ||
for k, v in pairs(dict) do | ||
table.insert(bulk, k) | ||
table.insert(bulk, v) | ||
end | ||
local first_updated_at = remove('first_updated_at') | ||
local last_updated_at = remove('last_updated_at') | ||
local file = remove('file') | ||
local file_hash = remove('file_hash') | ||
local ttl = remove('ttl') | ||
local file_length = remove('file_length') | ||
local hash_key = remove('hash_key') | ||
redis.call('HMSET', hash_key, 'file', file, 'file_hash', file_hash, 'file_length', file_length) | ||
return redis.call('HMSET', key, unpack(bulk)) | ||
end | ||
local payload = cjson.decode(redis.call('get', (KEYS[1]))) | ||
local ttl = payload.ttl | ||
local files_data = payload.files_data | ||
redis.call('DEL', KEYS[1]) | ||
for _, file_data in ipairs(files_data) do | ||
|
||
if (last_updated_at ~= cjson.null) then | ||
redis.call('HSET', hash_key, 'last_updated_at', last_updated_at) | ||
end | ||
local hash_key = file_data.hash_key | ||
local first_updated_at = file_data.meta.first_updated_at | ||
file_data.meta.first_updated_at = nil | ||
|
||
hmset(hash_key, file_data.meta) | ||
redis.call('HSETNX', hash_key, 'first_updated_at', first_updated_at) | ||
for line, coverage in pairs(hash_values) do | ||
if coverage == '-1' then | ||
redis.call("HSET", hash_key, line, coverage) | ||
else | ||
redis.call("HINCRBY", hash_key, line, coverage) | ||
end | ||
for line, coverage in pairs(file_data.coverage) do | ||
redis.call("HINCRBY", hash_key, line, coverage) | ||
end | ||
if ttl > -1 then | ||
print('ttl = ' .. inspect(ttl)) | ||
if ttl and ttl ~= cjson.null then | ||
redis.call("EXPIRE", hash_key, ttl) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters