Skip to content

Add counts and schema to next queue endpoint#94

Merged
goldlabelapps merged 1 commit intomasterfrom
staging
Apr 19, 2026
Merged

Add counts and schema to next queue endpoint#94
goldlabelapps merged 1 commit intomasterfrom
staging

Conversation

@goldlabelapps
Copy link
Copy Markdown
Owner

Refactor queue next route to build a base query/where clause and return richer metadata: fetch the next record, the filtered count, total count, and the queue table schema. Response payload now nests the record alongside filtered_count, total_count, schema and a message, and sets meta status/title accordingly. Also remove unused static asset app/static/python-logo.svg.

Refactor queue next route to build a base query/where clause and return richer metadata: fetch the next record, the filtered count, total count, and the queue table schema. Response payload now nests the record alongside filtered_count, total_count, schema and a message, and sets meta status/title accordingly. Also remove unused static asset app/static/python-logo.svg.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the /queue/next route to return richer queue metadata (next record plus counts and schema) alongside the record, and removes an unused static SVG asset.

Changes:

  • Refactored /queue/next to build a reusable WHERE clause and return record, filtered_count, total_count, and schema in a nested data payload.
  • Updated meta/title/message behavior for “record found” vs “no record” responses.
  • Removed app/static/python-logo.svg.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 5 comments.

File Description
app/api/queue/routes/next.py Adds filtered/total counts and schema to /queue/next response; refactors query composition.
app/static/python-logo.svg Removes an unused static asset.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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';")
Copy link

Copilot AI Apr 19, 2026

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.columns filtered only by table_name = 'queue'. In Postgres this can return columns from multiple schemas if another queue table exists on the DB (and it also makes results depend on search_path). Consider filtering by table_schema (e.g., 'public') and ordering by ordinal_position to make the returned schema deterministic.

Suggested change
cursor.execute("SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_name = 'queue';")
cursor.execute(
"SELECT column_name, data_type, is_nullable "
"FROM information_schema.columns "
"WHERE table_schema = 'public' AND table_name = 'queue' "
"ORDER BY ordinal_position;"
)

Copilot uses AI. Check for mistakes.
# 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()
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_nullable from information_schema.columns is returned as 'YES'/'NO', but the response field is named nullable, which reads like a boolean. Consider either converting this to a boolean (True/False) or renaming the field to something like is_nullable to match the underlying value and avoid surprising API consumers.

Suggested change
{"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 uses AI. Check for mistakes.
Comment on lines +39 to +54
# 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()
]
Copy link

Copilot AI Apr 19, 2026

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 uses AI. Check for mistakes.
Comment on lines +67 to +74
return {
"meta": make_meta("success" if record else "info", title),
"data": {
"record": record,
"filtered_count": filtered_count,
"total_count": total_count,
"schema": schema,
"message": None if record else "Nothing to show for the given filters."
Copy link

Copilot AI Apr 19, 2026

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 uses AI. Check for mistakes.
Comment on lines +67 to 75
return {
"meta": make_meta("success" if record else "info", title),
"data": {
"record": record,
"filtered_count": filtered_count,
"total_count": total_count,
"schema": schema,
"message": None if record else "Nothing to show for the given filters."
}
Copy link

Copilot AI Apr 19, 2026

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).

Copilot uses AI. Check for mistakes.
@goldlabelapps goldlabelapps merged commit 4237265 into master Apr 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants