membphis commented on code in PR #11840:
URL: https://github.com/apache/apisix/pull/11840#discussion_r1896531801
##########
apisix/consumer.lua:
##########
@@ -186,24 +204,43 @@ function _M.consumers()
end
-local function create_consume_cache(consumers_conf, key_attr)
+local create_consume_cache
+do
+ local consumers_plugin_key_lrucache_tab = {}
+
+local function create_new_consumer(consumer)
+ local new_consumer = core.table.clone(consumer)
+ new_consumer.auth_conf = secret.fetch_secrets(new_consumer.auth_conf,
false)
+ return new_consumer
+end
+
+
+function create_consume_cache(consumers_conf, key_attr, plugin_name)
local consumer_names = {}
+ local lru_cache = consumers_plugin_key_lrucache_tab[plugin_name]
+ if lru_cache == nil then
+ lru_cache = core.lrucache.new({
+ ttl = 60 * 60 * 24, count = 20480
+ })
+ consumers_plugin_key_lrucache_tab[plugin_name] = lru_cache
+ end
for _, consumer in ipairs(consumers_conf.nodes) do
core.log.info("consumer node: ", core.json.delay_encode(consumer))
- local new_consumer = core.table.clone(consumer)
- new_consumer.auth_conf = secret.fetch_secrets(new_consumer.auth_conf,
true,
-
new_consumer.auth_conf, "")
- consumer_names[new_consumer.auth_conf[key_attr]] = new_consumer
+ local new_consumer = lru_cache(consumer.auth_conf[key_attr],
Review Comment:
I think: this should be enough, and it seems easier
```suggestion
local new_consumer = lru_cache(consumer, nil, create_new_consumer,
consumer)
```
##########
apisix/consumer.lua:
##########
@@ -101,10 +104,19 @@ local function plugin_consumer()
if not plugins[name] then
plugins[name] = {
nodes = {},
+ len = 0,
conf_version = consumers.conf_version
}
end
+ local cached_consumer = consumers_id_cache[val.value.id]
Review Comment:
I do not know why we have to add `consumers_id_cache `
it seems useless
##########
apisix/consumer.lua:
##########
@@ -101,10 +104,19 @@ local function plugin_consumer()
if not plugins[name] then
plugins[name] = {
nodes = {},
+ len = 0,
conf_version = consumers.conf_version
}
end
+ local cached_consumer = consumers_id_cache[val.value.id]
+ if cached_consumer and
+ cached_consumer.modifiedIndex == val.modifiedIndex then
+ plugins[name].len = plugins[name].len + 1
+ core.table.insert(plugins[name].nodes, plugins[name].len,
+ cached_consumer)
+ goto CONTINUE_INTERNAL
Review Comment:
shorter is better
```suggestion
goto CONTINUE
```
##########
apisix/consumer.lua:
##########
@@ -186,24 +204,43 @@ function _M.consumers()
end
-local function create_consume_cache(consumers_conf, key_attr)
+local create_consume_cache
+do
+ local consumers_plugin_key_lrucache_tab = {}
+
+local function create_new_consumer(consumer)
Review Comment:
we need a better name, it is not creating a new consumer
it should be `transform` or `fill secret`, what do you think?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]