mirror of
https://github.com/open-webui/open-webui.git
synced 2026-08-27 16:04:50 -06:00
refac: drop the redundant .keys() from two dict membership tests (#28859)
`x in d` and `x in d.keys()` are identical for a plain dict, so the `.keys()` call builds a throwaway view and reads as if it were doing something. Both sites operate on a plain dict: `combined` in `merge_and_sort_query_results` is a local `dict()`, and `ui_settings` comes from `UserSettings.model_dump()` where `ui` is annotated `dict | None` and is already guarded against None on the preceding line. No behaviour change, and no measurable speedup either, so this is a readability cleanup rather than a performance one. Sites where `.keys()` is load-bearing are left alone: the `list(d.keys())` snapshots taken before mutating during iteration, and the places where `.keys()` is the iteration or comprehension source rather than a membership test.
This commit is contained in:
@@ -641,7 +641,7 @@ def merge_and_sort_query_results(query_results: list[dict], k: int) -> dict:
|
||||
if isinstance(document, str):
|
||||
doc_hash = (metadata or {}).get(CHUNK_HASH_KEY) or _content_hash(document)
|
||||
|
||||
if doc_hash not in combined.keys():
|
||||
if doc_hash not in combined:
|
||||
combined[doc_hash] = (distance, document, metadata)
|
||||
continue # if doc is new, no further comparison is needed
|
||||
|
||||
|
||||
@@ -515,7 +515,7 @@ async def update_user_settings_by_session_user(
|
||||
if (
|
||||
user.role != 'admin'
|
||||
and ui_settings is not None
|
||||
and 'toolServers' in ui_settings.keys()
|
||||
and 'toolServers' in ui_settings
|
||||
and not await has_permission(
|
||||
user.id,
|
||||
'features.direct_tool_servers',
|
||||
|
||||
Reference in New Issue
Block a user