Skip to content

Commit

Permalink
perf: add sharetable queryall default behavior(all share data) (#1537)
Browse files Browse the repository at this point in the history
  • Loading branch information
JieTrancender authored Feb 16, 2022
1 parent 40ee98b commit eaba8f9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lualib/skynet/sharetable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,27 @@ local function sharetable_service()
skynet.ret(skynet.pack(ptr))
end

function sharetable.queryall(source, filenamelist)
local ptrList = {}
local function querylist(source, filenamelist)
local ptrList = {}
for _, filename in ipairs(filenamelist) do
if files[filename] then
ptrList[filename] = query_file(source, filename)
end
end
return ptrList
end

local function queryall(source)
local ptrList = {}
for filename in pairs(files) do
ptrList[filename] = query_file(source, filename)
end
return ptrList
end

function sharetable.queryall(source, filenamelist)
local queryFunc = filenamelist and querylist or queryall
local ptrList = queryFunc(source, filenamelist)
skynet.ret(skynet.pack(ptrList))
end

Expand Down
9 changes: 9 additions & 0 deletions test/testsharetable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ local sharetable = require "skynet.sharetable"
local function queryall_test()
sharetable.loadtable("test_one", {["message"] = "hello one", x = 1, 1})
sharetable.loadtable("test_two", {["message"] = "hello two", x = 2, 2})
sharetable.loadtable("test_three", {["message"] = "hello three", x = 3, 3})
local list = sharetable.queryall({"test_one", "test_two"})
for filename, tbl in pairs(list) do
for k, v in pairs(tbl) do
print(filename, k, v)
end
end

print("test queryall default")
local defaultlist = sharetable.queryall()
for filename, tbl in pairs(defaultlist) do
for k, v in pairs(tbl) do
print(filename, k, v)
end
end
end

skynet.start(function()
Expand Down

0 comments on commit eaba8f9

Please sign in to comment.