Skip to content

Commit

Permalink
rpc.lua style clean
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Oct 27, 2024
1 parent 712de50 commit 15aaf33
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions kong/clustering/services/sync/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ function _M:init_cp(manager)
rpc_peers = kong.rpc:get_peers()
end

local default_namespace
for namespace, v in pairs(current_versions) do
if namespace == "default" then
default_namespace = v
break
end
end
local default_namespace = current_versions.default

if not default_namespace then
return nil, "default namespace does not exist inside params"
Expand Down Expand Up @@ -128,7 +122,7 @@ function _M:init_cp(manager)
end

-- some deltas are returned, are they contiguous?
if res[1].version == default_namespace.version + 1 then
if res[1].version == default_namespace_version + 1 then
-- doesn't wipe dp lmdb, incremental sync
return gen_delta_result(res, false)
end
Expand Down Expand Up @@ -201,28 +195,22 @@ local function do_sync()
return true
end

local ns_delta

for namespace, delta in pairs(ns_deltas) do
if namespace == "default" then
ns_delta = delta
break -- should we break here?
end
end

local ns_delta = ns_deltas.default
if not ns_delta then
return nil, "default namespace does not exist inside params"
end

if isempty(ns_delta.deltas) then
local deltas = ns_delta.deltas

if isempty(deltas) then
ngx_log(ngx_DEBUG, "no delta to sync")
return true
end

-- we should find the correct default workspace
-- and replace the old one with it
local default_ws_changed
for _, delta in ipairs(ns_delta.deltas) do
for _, delta in ipairs(deltas) do
if delta.type == "workspaces" and delta.row.name == "default" then
kong.default_workspace = delta.row.id
default_ws_changed = true
Expand All @@ -245,7 +233,7 @@ local function do_sync()
local crud_events = {}
local crud_events_n = 0

for _, delta in ipairs(ns_delta.deltas) do
for _, delta in ipairs(deltas) do
local delta_type = delta.type
local delta_row = delta.row
local ev
Expand Down

0 comments on commit 15aaf33

Please sign in to comment.