Skip to content

Commit efdb387

Browse files
author
Foo Bar
committed
update comments
1 parent e654aba commit efdb387

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

apisix/core/config_yaml.lua

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -174,28 +174,26 @@ local function sync_data(self)
174174

175175
if self.values and #self.values > 0 then
176176
if is_use_admin_api() then
177-
-- used to delete values that do not exist in the new list.
178-
-- only when using modifiedIndex, old values need to be retained.
179-
-- If modifiedIndex changes, old values need to be removed and cleaned up.
180-
local exist_modifiedIndex_items = {}
177+
-- filter self.values to retain only those whose IDs exist in the new items list.
178+
local exist_values = new_tab(8, 0)
179+
self.values_hash = new_tab(0, 8)
180+
181+
local exist_items = {}
181182
for _, item in ipairs(items) do
182-
if item.modifiedIndex then
183-
exist_modifiedIndex_items[tostring(item.id)] = true
184-
end
183+
exist_items[tostring(item.id)] = true
185184
end
186-
187-
local new_values = new_tab(8, 0)
188-
self.values_hash = new_tab(0, 8)
185+
-- remove objects that exist in the self.values but do not exist in the new items.
186+
-- for removed items, trigger cleanup handlers.
189187
for _, item in ipairs(self.values) do
190188
local id = item.value.id
191-
if not exist_modifiedIndex_items[id] then
189+
if not exist_items[id] then
192190
config_util.fire_all_clean_handlers(item)
193191
else
194-
insert_tab(new_values, item)
195-
self.values_hash[id] = #new_values
192+
insert_tab(exist_values, item)
193+
self.values_hash[id] = #exist_values
196194
end
197195
end
198-
self.values = new_values
196+
self.values = exist_values
199197
else
200198
for _, item in ipairs(self.values) do
201199
config_util.fire_all_clean_handlers(item)
@@ -287,9 +285,7 @@ local function sync_data(self)
287285
-- remove the old item
288286
local pre_val = self.values[pre_index]
289287
if pre_val and
290-
(not pre_val.modifiedIndex or pre_val.modifiedIndex ~= modifiedIndex) then
291-
log.error("fire all clean handlers for ", self.key, " id: ", id,
292-
" modifiedIndex: ", modifiedIndex)
288+
(not item.modifiedIndex or pre_val.modifiedIndex ~= item.modifiedIndex) then
293289
config_util.fire_all_clean_handlers(pre_val)
294290
self.values[pre_index] = conf_item
295291
conf_item.value.id = item_id

0 commit comments

Comments
 (0)