mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-16 04:28:36 +00:00
fix(utils): Switch throttle decorator to async
After migration to async db operations, the throttle decorator also needs to support async. Since the decorator is only used for async funcs now, we can just switch it to async instead of supporting sync and async at the same time. Signed-off-by: Adam Tao <tcx4c70@gmail.com>
This commit is contained in:
parent
f162d4de90
commit
5687f0c594
1 changed files with 3 additions and 3 deletions
|
|
@ -843,9 +843,9 @@ def throttle(interval: float = 10.0):
|
|||
last_calls = {}
|
||||
lock = threading.Lock()
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
async def wrapper(*args, **kwargs):
|
||||
if interval is None:
|
||||
return func(*args, **kwargs)
|
||||
return await func(*args, **kwargs)
|
||||
|
||||
key = (args, freeze(kwargs))
|
||||
now = time.time()
|
||||
|
|
@ -855,7 +855,7 @@ def throttle(interval: float = 10.0):
|
|||
if now - last_calls.get(key, 0) < interval:
|
||||
return None
|
||||
last_calls[key] = now
|
||||
return func(*args, **kwargs)
|
||||
return await func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue