Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(router): use resty.core.utils.str_replace_char() for dashes #11721

Merged
merged 14 commits into from
Oct 24, 2023

Conversation

chronolaw
Copy link
Contributor

@chronolaw chronolaw commented Oct 10, 2023

Summary

resty.core.utils.str_replace_char() is a better way to replace - to _.
In the future string.lua will gather more functions to simplify tools.utils.lua.

See: #10443

Checklist

  • The Pull Request has tests
  • A changelog file has been created under changelog/unreleased/kong or skip-changelog label added on PR if changelog is unnecessary. README.md
  • There is a user-facing docs PR against https://github.com/Kong/docs.konghq.com - PUT DOCS PR HERE

Full changelog

  • [Implement ...]

Issue reference

Fix #[issue number]

@pull-request-size pull-request-size bot added size/M and removed size/S labels Oct 10, 2023
@chronolaw chronolaw marked this pull request as ready for review October 10, 2023 02:45
@chronolaw chronolaw force-pushed the perf/use_resty_core_str_replace_char branch from 44d205a to 5f0a044 Compare October 12, 2023 08:11
@chobits
Copy link
Contributor

chobits commented Oct 23, 2023

hi @chronolaw

It seems there are some other files needed to be fixed. see the following matched files:

 $ grep '"-".*"_"' -R kong|grep gsub|grep -v cscope.out
kong/runloop/plugin_servers/process.lua:      local env_prefix = "pluginserver_" .. name:gsub("-", "_")
kong/plugins/datadog/handler.lua:    return consumer and gsub(consumer.id, "-", "_")
kong/clustering/compat/init.lua:      local name = gsub(t["name"], "-", "_")
kong/clustering/compat/checkers.lua:            local new_prefix = prefix:gsub("-", "_")
kong/vaults/env/init.lua:  resource = upper(gsub(resource, "-", "_"))
kong/pdk/vault.lua:        local env_name = gsub(name, "-", "_")
kong/pdk/vault.lua:          local n = lower(fmt("vault_%s_%s", env_name, gsub(k, "-", "_")))
kong/pdk/service/response.lua:        local var = fmt("upstream_http_%s", gsub(lower(name), "-", "_"))
kong/pdk/service/response.lua:      name = gsub(name, "-", "_")
kong/pdk/service/response.lua:        n = gsub(lower(n), "-", "_")
kong/router/atc.lua:      local name = name:gsub("-", "_"):lower()
kong/router/compat.lua:        local name = "any(http.headers." .. h:gsub("-", "_"):lower() .. ")"

@chronolaw
Copy link
Contributor Author

chronolaw commented Oct 23, 2023

Yes, replace_dashes is a very common operation, but I don't want to change too many source, which is hard to review.

This PR focus on router scope only, after this PR is merged, we can optimize other soucres.

kong/tools/string.lua Show resolved Hide resolved
@chronolaw chronolaw force-pushed the perf/use_resty_core_str_replace_char branch from 132baf1 to 258cf95 Compare October 24, 2023 03:29
@windmgc windmgc merged commit 59670a1 into master Oct 24, 2023
23 checks passed
@windmgc windmgc deleted the perf/use_resty_core_str_replace_char branch October 24, 2023 04:48
windmgc pushed a commit that referenced this pull request Oct 25, 2023
…ub` (#11823)

It is a sister PR of #11721, optimize the code of pdk.
chronolaw added a commit that referenced this pull request Jan 23, 2024
…11721)

resty.core.utils.str_replace_char() is a better way to replace - to _.
In the future string.lua will gather more functions to simplify tools.utils.lua.

See: #10443
chronolaw added a commit that referenced this pull request Jan 24, 2024
…11721)

resty.core.utils.str_replace_char() is a better way to replace - to _.
In the future string.lua will gather more functions to simplify tools.utils.lua.

See: #10443
chronolaw added a commit that referenced this pull request Feb 26, 2024
…11721)

resty.core.utils.str_replace_char() is a better way to replace - to _.
In the future string.lua will gather more functions to simplify tools.utils.lua.

See: #10443
chronolaw added a commit that referenced this pull request Feb 26, 2024
…11721)

resty.core.utils.str_replace_char() is a better way to replace - to _.
In the future string.lua will gather more functions to simplify tools.utils.lua.

See: #10443
chronolaw added a commit that referenced this pull request Mar 4, 2024
…11721)

resty.core.utils.str_replace_char() is a better way to replace - to _.
In the future string.lua will gather more functions to simplify tools.utils.lua.

See: #10443
locao pushed a commit that referenced this pull request Mar 5, 2024
…11721)

resty.core.utils.str_replace_char() is a better way to replace - to _.
In the future string.lua will gather more functions to simplify tools.utils.lua.

See: #10443
ADD-SP pushed a commit that referenced this pull request Mar 7, 2024
…11721)

resty.core.utils.str_replace_char() is a better way to replace - to _.
In the future string.lua will gather more functions to simplify tools.utils.lua.

See: #10443
ADD-SP pushed a commit that referenced this pull request Mar 7, 2024
…11721)

resty.core.utils.str_replace_char() is a better way to replace - to _.
In the future string.lua will gather more functions to simplify tools.utils.lua.

See: #10443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants