-
Notifications
You must be signed in to change notification settings - Fork 0
Add counts and schema to next queue endpoint #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,7 +18,7 @@ def get_next_queue( | |||||
| cursor = conn.cursor() | ||||||
|
|
||||||
| # Build query with optional filters | ||||||
| query = "SELECT * FROM queue" | ||||||
| base_query = "SELECT * FROM queue" | ||||||
| filters = [] | ||||||
| params = [] | ||||||
| if collection: | ||||||
|
|
@@ -27,34 +27,52 @@ def get_next_queue( | |||||
| if group: | ||||||
| filters.append('"group" = %s') | ||||||
| params.append(group) | ||||||
| if filters: | ||||||
| query += " WHERE " + " AND ".join(filters) | ||||||
| query += " ORDER BY updated DESC LIMIT 1;" | ||||||
| where_clause = (" WHERE " + " AND ".join(filters)) if filters else "" | ||||||
|
|
||||||
| # 1. Get the next record | ||||||
| query = base_query + where_clause + " ORDER BY updated DESC LIMIT 1;" | ||||||
| cursor.execute(query, params) | ||||||
| row = cursor.fetchone() | ||||||
| columns = [desc[0] for desc in cursor.description] if cursor.description else [] | ||||||
| record = dict(zip(columns, row)) if row and columns else None | ||||||
|
|
||||||
| # 2. Get count of records matching filters | ||||||
| count_query = "SELECT COUNT(*) FROM queue" + where_clause + ";" | ||||||
| cursor.execute(count_query, params) | ||||||
| filtered_row = cursor.fetchone() | ||||||
| filtered_count = filtered_row[0] if filtered_row else 0 | ||||||
|
|
||||||
| # 3. Get total count | ||||||
| cursor.execute("SELECT COUNT(*) FROM queue;") | ||||||
| total_row = cursor.fetchone() | ||||||
| total_count = total_row[0] if total_row else 0 | ||||||
|
|
||||||
| # 4. Get table schema | ||||||
| cursor.execute("SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_name = 'queue';") | ||||||
| schema = [ | ||||||
| {"name": row[0], "type": row[1], "nullable": row[2]} for row in cursor.fetchall() | ||||||
|
||||||
| {"name": row[0], "type": row[1], "nullable": row[2]} for row in cursor.fetchall() | |
| {"name": row[0], "type": row[1], "nullable": row[2] == "YES"} for row in cursor.fetchall() |
Copilot
AI
Apr 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This endpoint now runs 4 separate DB queries on every request (next record, filtered count, total count, schema). The two COUNT(*) queries can be combined into a single query (e.g., using subqueries or FILTER), and the schema query is a good candidate for caching since table schemas rarely change at runtime. Without this, /queue/next could become noticeably slower on large tables/high traffic.
Copilot
AI
Apr 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/queue/next appears to be unauthenticated, and the response now includes full table schema details. If this API is exposed beyond trusted/internal users, this increases information disclosure risk. Consider protecting this route (e.g., API key dependency like other DB/LLM routes) or gating/removing schema from the default response.
Copilot
AI
Apr 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are existing FastAPI endpoint tests for /queue (tests/test_queue.py), but there’s no coverage for /queue/next. Since this change alters the response contract (nested data.record plus filtered_count, total_count, and schema), please add tests that validate the new shape for both the “record found” and “no record” cases (including filter parameters).
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The schema lookup uses
information_schema.columnsfiltered only bytable_name = 'queue'. In Postgres this can return columns from multiple schemas if anotherqueuetable exists on the DB (and it also makes results depend onsearch_path). Consider filtering bytable_schema(e.g.,'public') and ordering byordinal_positionto make the returned schema deterministic.