fix(events): bound provider prefix recent query
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Failing after 3m48s
CD Pipeline / build-and-deploy (push) Has been skipped
CD Pipeline / post-deploy-checks (push) Has been skipped
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Failing after 3m48s
CD Pipeline / build-and-deploy (push) Has been skipped
CD Pipeline / post-deploy-checks (push) Has been skipped
This commit is contained in:
@@ -7310,6 +7310,23 @@ async def get_run_detail(
|
||||
# Channel Events
|
||||
# =============================================================================
|
||||
|
||||
|
||||
def _exclusive_text_prefix_upper_bound(prefix: str) -> str:
|
||||
if not prefix:
|
||||
return ""
|
||||
last = ord(prefix[-1])
|
||||
if last >= 0x10FFFF:
|
||||
return ""
|
||||
return f"{prefix[:-1]}{chr(last + 1)}"
|
||||
|
||||
|
||||
def _provider_event_id_prefix_bounds(provider_prefix: str) -> tuple[str, str]:
|
||||
prefix = provider_prefix.strip().lower()
|
||||
if prefix and ":" not in prefix:
|
||||
prefix = f"{prefix}:"
|
||||
return prefix, _exclusive_text_prefix_upper_bound(prefix)
|
||||
|
||||
|
||||
async def list_recent_channel_events(
|
||||
*,
|
||||
project_id: str | None,
|
||||
@@ -7332,23 +7349,17 @@ async def list_recent_channel_events(
|
||||
if channel_type is not None:
|
||||
stmt = stmt.where(AwoooPConversationEvent.channel_type == channel_type)
|
||||
if recent_provider_prefix is not None:
|
||||
if ":" in recent_provider_prefix:
|
||||
prefix_lower, prefix_upper = _provider_event_id_prefix_bounds(
|
||||
recent_provider_prefix
|
||||
)
|
||||
if prefix_lower:
|
||||
stmt = stmt.where(
|
||||
AwoooPConversationEvent.provider_event_id.like(
|
||||
f"{provider_prefix.strip()}%"
|
||||
)
|
||||
AwoooPConversationEvent.provider_event_id >= prefix_lower
|
||||
)
|
||||
else:
|
||||
stmt = stmt.where(
|
||||
text(
|
||||
"LOWER(COALESCE("
|
||||
"NULLIF(source_envelope->>'provider', ''), "
|
||||
"NULLIF(split_part(provider_event_id, ':', 1), ''), "
|
||||
"channel_type"
|
||||
")) = :recent_provider_prefix"
|
||||
if prefix_upper:
|
||||
stmt = stmt.where(
|
||||
AwoooPConversationEvent.provider_event_id < prefix_upper
|
||||
)
|
||||
)
|
||||
stmt = stmt.params(recent_provider_prefix=recent_provider_prefix)
|
||||
stmt = stmt.order_by(
|
||||
AwoooPConversationEvent.received_at.desc(),
|
||||
AwoooPConversationEvent.event_id.desc(),
|
||||
|
||||
Reference in New Issue
Block a user