forked from opentibiabr/canary
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve: checking for duplicate storage keys (opentibiabr#2180)
Removed all duplicate code and added a new function to global to check storage keys, any table can be checked. This makes maintenance easier and avoids duplicate codes. --------- Co-authored-by: GitHub Actions <github-actions[bot]@users.noreply.github.com> Co-authored-by: Elson Costa <[email protected]>
- Loading branch information
1 parent
6e134e3
commit 01aeed1
Showing
4 changed files
with
37 additions
and
78 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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
-- Function to check for duplicate keys in a given variable's storage | ||
local function checkDuplicateStorageKeys(varName) | ||
local keys = _G[varName] | ||
local seen = {} | ||
local duplicates = {} | ||
|
||
for k, v in pairs(keys) do | ||
if seen[v] then | ||
table.insert(duplicates, v) | ||
else | ||
seen[v] = true | ||
end | ||
end | ||
|
||
return next(duplicates) and duplicates or false | ||
end | ||
|
||
-- Function to check duplicated variable keys and log the results | ||
local function checkAndLogDuplicateKeys(variableNames) | ||
for _, variableName in ipairs(variableNames) do | ||
local duplicates = checkDuplicateStorageKeys(variableName) | ||
if duplicates then | ||
local message = "Duplicate keys found: " .. table.concat(duplicates, ", ") | ||
logger.warn("Checking " .. variableName .. ": " .. message) | ||
else | ||
logger.info("Checking " .. variableName .. ": No duplicate keys found.") | ||
end | ||
end | ||
end | ||
|
||
local startup = GlobalEvent("Server Initialization") | ||
|
||
function startup.onStartup() | ||
checkAndLogDuplicateKeys({ "Global", "GlobalStorage", "Storage" }) | ||
end | ||
|
||
startup:register() |