mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Add memoization to lazy param parsing
This commit is contained in:
parent
4ee4b66135
commit
043d1c8aa2
2 changed files with 5 additions and 3 deletions
|
@ -2,7 +2,6 @@
|
|||
# information such as params, content_type e.g
|
||||
class HTTP::Server
|
||||
class Context
|
||||
|
||||
def params
|
||||
@request.url_params = route_lookup.params
|
||||
@params ||= Kemal::ParamParser.new(@request)
|
||||
|
|
|
@ -18,7 +18,12 @@ class Kemal::ParamParser
|
|||
|
||||
{% for method in %w(url query body json) %}
|
||||
def {{method.id}}
|
||||
# check memoization
|
||||
return @{{method.id}} if @{{method.id}}_parsed
|
||||
|
||||
parse_{{method.id}}
|
||||
# memoize
|
||||
@{{method.id}}_parsed = true
|
||||
@{{method.id}}
|
||||
end
|
||||
{% end %}
|
||||
|
@ -67,6 +72,4 @@ class Kemal::ParamParser
|
|||
end
|
||||
part_params
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue