Skip to content

Commit

Permalink
clean sync postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Oct 12, 2024
1 parent d1b67e5 commit 6c7f851
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions kong/clustering/services/sync/strategies/postgres.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ local PURGE_QUERY = [[


function _M:init_worker()
ngx.timer.every(CLEANUP_TIME_DELAY, function(premature)
local function cleanup_handler(premature)
if premature then
ngx_log(ngx_DEBUG, "[incremental] worker exiting, killing incremental cleanup timer")

Expand All @@ -54,7 +54,9 @@ function _M:init_worker()

ngx_log(ngx_DEBUG,
"[incremental] successfully purged old data from incremental delta table")
end)
end

assert(ngx.timer.every(CLEANUP_TIME_DELAY, cleanup_handler))
end


Expand All @@ -74,13 +76,15 @@ local NEW_VERSION_QUERY = [[
-- { type = "route", "id" = "0a5bac5c-b795-4981-95d2-919ba3390b7e", "ws_id" = "73478cf6-964f-412d-b1c4-8ac88d9e85e9", row = "JSON", }
-- }
function _M:insert_delta(deltas)
local escape_literal = self.connector:escape_literal

local buf = buffer.new()
for _, d in ipairs(deltas) do
buf:putf("(new_version, %s, %s, %s, %s)",
self.connector:escape_literal(d.type),
self.connector:escape_literal(d.id),
self.connector:escape_literal(d.ws_id),
self.connector:escape_literal(cjson_encode(d.row)))
escape_literal(d.type),
escape_literal(d.id),
escape_literal(d.ws_id),
escape_literal(cjson_encode(d.row)))
end

local sql = string_format(NEW_VERSION_QUERY, buf:get())
Expand All @@ -97,7 +101,7 @@ function _M:get_latest_version()
return nil, err
end

return res[1].max_version
return res[1] and res[1].max_version
end


Expand Down

0 comments on commit 6c7f851

Please sign in to comment.