feat: add priority filtering and sort stability to V3 Lookup System

This commit is contained in:
Scott Idem
2026-02-20 17:18:21 -05:00
parent 6bfbff309a
commit 48fc97cf46
5 changed files with 74 additions and 17 deletions

View File

@@ -12,22 +12,17 @@ def get_lookup_list_v3(
for_type: Optional[str] = None,
for_id: Optional[int] = None,
include_disabled: bool = False,
whitelist: Optional[List[str]] = None
whitelist: Optional[List[str]] = None,
only_priority: bool = False
) -> List[dict]:
"""
Retrieves a ranked, deduplicated list of lookup records.
Priority: Object Override > Account Override > Global Default.
Supports an optional whitelist (List of 'group' strings).
Supports an optional whitelist and priority filtering.
"""
table_name = f"v_lu_v3_{lu_type}"
# We use ROW_NUMBER() to handle the hierarchy
# 1. Object specific (matching for_type and for_id)
# 2. Account specific (matching account_id)
# 3. Global (account_id IS NULL)
# Whitelist logic: If a whitelist is provided, we only want records where
# the group is in that list.
sql = f"""
SELECT * FROM (
@@ -56,7 +51,10 @@ def get_lookup_list_v3(
if not include_disabled:
sql += " AND enable = 1"
sql += " ORDER BY sort ASC, name ASC"
if only_priority:
sql += " AND priority = 1"
sql += " ORDER BY COALESCE(priority, 0) DESC, COALESCE(sort, 0) DESC, name ASC"
params = {
"account_id": account_ctx.account_id,

View File

@@ -20,6 +20,7 @@ async def get_v3_lookup_list(
for_id: Optional[int] = Query(None),
site_id: Optional[str] = Query(None, min_length=8, max_length=22),
include_disabled: bool = Query(False),
only_priority: bool = Query(False),
account_ctx: AccountContext = Depends(get_account_context),
response: Response = Response
):
@@ -55,7 +56,8 @@ async def get_v3_lookup_list(
for_type=for_type,
for_id=for_id,
include_disabled=include_disabled,
whitelist=whitelist
whitelist=whitelist,
only_priority=only_priority
)
if not results and not include_disabled: