forked from lbovet/vertx-rest-storage
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDCISA-13736] Fix bad habits in analyze-pathsize.lua.
- Loading branch information
1 parent
1b13c2f
commit 50232a4
Showing
1 changed file
with
47 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,48 @@ | ||
local sep = ":"; | ||
local toAnalyze = KEYS[1] | ||
local resourcesPrefix = ARGV[1] | ||
local collectionsPrefix = ARGV[2] | ||
|
||
local resourceCount = 0 | ||
local resourcesSize = 0 | ||
|
||
local function analyzeChildrenAndItself(path) | ||
if redis.call('exists',resourcesPrefix..path) == 1 then | ||
local res_size = redis.call('hget', resourcesPrefix..path, 'resource') | ||
resourceCount = resourceCount + 1 | ||
resourcesSize = resourcesSize + string.len(res_size) | ||
elseif redis.call('exists',collectionsPrefix..path) == 1 then | ||
local members = redis.call('zrangebyscore',collectionsPrefix..path,'-inf','+inf') | ||
for key,value in pairs(members) do | ||
local pathToAnalyze = path..":"..value | ||
analyzeChildrenAndItself(pathToAnalyze) | ||
end | ||
else | ||
redis.log(redis.LOG_WARNING, "can't analyze resource from type: "..path) | ||
end | ||
end | ||
|
||
local function round(num, dp) | ||
return string.format("%."..(dp or 0).."f", num) | ||
end | ||
|
||
local function toHumanReadable(size) | ||
if size >= 1048576 then | ||
local mbs = round(size / 1048576, 2) | ||
return mbs.." MB" | ||
elseif size >= 1024 then | ||
local kbs = round(size / 1024, 2) | ||
return kbs.." KB" | ||
else | ||
return size.." Bytes" | ||
end | ||
end | ||
|
||
if "/" == toAnalyze then | ||
toAnalyze = "" | ||
end | ||
|
||
analyzeChildrenAndItself(toAnalyze) | ||
|
||
local sep = ":"; | ||
local toAnalyze = KEYS[1] | ||
local resourcesPrefix = ARGV[1] | ||
local collectionsPrefix = ARGV[2] | ||
|
||
local resourceCount = 0 | ||
local resourcesSize = 0 | ||
|
||
local function analyzeChildrenAndItself(path) | ||
local pathAbs = resourcesPrefix .. path | ||
if redis.call('exists',pathAbs) == 1 then | ||
local res_size = redis.call('hget', pathAbs, 'resource') | ||
resourceCount = resourceCount + 1 | ||
resourcesSize = resourcesSize + string.len(res_size) | ||
elseif redis.call('exists',pathAbs) == 1 then | ||
local members = redis.call('zrangebyscore',pathAbs,'-inf','+inf') | ||
for key,value in pairs(members) do | ||
local pathToAnalyze = path..":"..value | ||
analyzeChildrenAndItself(pathToAnalyze) | ||
end | ||
else | ||
redis.log(redis.LOG_WARNING, "can't analyze resource from type: "..path) | ||
end | ||
end | ||
|
||
local function round(num, dp) | ||
return string.format("%."..(dp or 0).."f", num) | ||
end | ||
|
||
local function toHumanReadable(size) | ||
if size >= 1048576 then | ||
local mbs = round(size / 1048576, 2) | ||
return mbs.." MB" | ||
elseif size >= 1024 then | ||
local kbs = round(size / 1024, 2) | ||
return kbs.." KB" | ||
else | ||
return size.." Bytes" | ||
end | ||
end | ||
|
||
if "/" == toAnalyze then | ||
toAnalyze = "" | ||
end | ||
|
||
analyzeChildrenAndItself(toAnalyze) | ||
|
||
return "Found "..resourceCount.." resources with total size of "..toHumanReadable(resourcesSize) |