Created
October 29, 2020 13:29
-
-
Save koshoi/c88e6e54bc0506894351fe1ca15de4c8 to your computer and use it in GitHub Desktop.
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
_G.ls = setmetatable({}, { | |
__serialize = function() | |
local res = {} | |
for _, sp_info in box.space._space:pairs(512, { iterator = "GE" }) do | |
local sp = box.space[sp_info.name] | |
local info = {} | |
info.name = tostring(sp.name) | |
info.engine = tostring(sp.engine) | |
info.len = tostring(sp:len()) | |
info.bsize = sp:bsize() | |
info.owner = tostring(box.space._user:get(sp_info.owner).name) | |
-- index numeration starts with zero | |
if next(sp.index) then | |
for k, v in pairs(sp.index) do | |
if type(k) == 'number' then | |
info.bsize = info.bsize + v:bsize() | |
end | |
end | |
end | |
info.bsize = tostring(info.bsize):sub(1, -4) -- strip ULL | |
table.insert(res, info) | |
end | |
table.sort(res, function(a, b) return a.engine .. a.name < b.engine .. b.name end) | |
--do return res end | |
local nice = {} | |
local nice_l = {} | |
for _, sp in pairs(res) do | |
for k, v in pairs(sp) do | |
if not nice_l[k] then | |
nice_l[k] = 0 | |
end | |
nice_l[k] = math.max(nice_l[k], v:len()) | |
end | |
end | |
local split_size = tonumber(rawget(_G, '__LS_SPLIT_SIZE')) or 2 | |
for _, sp in pairs(res) do | |
local str = '' | |
for _, k in pairs({ 'engine', 'owner', 'bsize', 'len' }) do | |
str = str .. ("%% -%ds%% %ds"):format(nice_l[k], split_size):format(sp[k], " ") | |
end | |
str = str .. sp['name'] | |
table.insert(nice, str) | |
end | |
return nice | |
end; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment