Skip to content

Commit c31b33a

Browse files
committed
perf patch schema
1 parent 1940cf4 commit c31b33a

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

apisix/admin/standalone.lua

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ function _M.run()
240240
end
241241

242242

243-
local schema_patch
243+
local patch_schema
244244
do
245245
local resource_schema = {
246246
"proto",
@@ -254,18 +254,38 @@ do
254254
"ssl",
255255
"plugin_config",
256256
}
257-
function schema_patch()
257+
local function attach_modifiedIndex_schema(name)
258+
local schema = core.schema[name]
259+
if not schema then
260+
core.log.error("schema for ", name, " not found")
261+
return
262+
end
263+
if schema.properties and not schema.properties.modifiedIndex then
264+
schema.properties.modifiedIndex = {
265+
type = "integer",
266+
}
267+
end
268+
end
269+
270+
local function patch_credential_schema()
271+
local credential_schema = core.schema["credential"]
272+
if credential_schema and credential_schema.properties then
273+
credential_schema.properties.id = {
274+
type = "string",
275+
minLength = 15,
276+
maxLength = 128,
277+
pattern = [[^[a-zA-Z0-9]+/credentials/[a-zA-Z0-9]+$]],
278+
}
279+
end
280+
end
281+
282+
function patch_schema()
283+
-- attach modifiedIndex schema to all resource schemas
258284
for _, name in ipairs(resource_schema) do
259-
local schema = core.schema[name]
260-
if not schema then
261-
core.log.error("schema for ", name, " not found")
262-
end
263-
if schema and schema.properties then
264-
schema.properties.modifiedIndex = {
265-
type = "integer",
266-
}
267-
end
285+
attach_modifiedIndex_schema(name)
268286
end
287+
-- patch credential schema
288+
patch_credential_schema()
269289
end
270290
end
271291

@@ -287,7 +307,7 @@ function _M.init_worker()
287307
end
288308
events:register(update_config, EVENT_UPDATE, EVENT_UPDATE)
289309

290-
schema_patch()
310+
patch_schema()
291311
end
292312

293313

0 commit comments

Comments
 (0)