Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""NX AI - FastAPI/Python/Postgres/tsvector"""

# Current Version
__version__ = "1.1.5"
__version__ = "1.1.6"
23 changes: 15 additions & 8 deletions app/api/prospects/prospects.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
from app.utils.db import get_db_connection

router = APIRouter()


Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

There’s trailing whitespace on this blank line, which tends to cause avoidable diffs/lint noise. Please remove the extra spaces.

Suggested change

Copilot uses AI. Check for mistakes.
base_url = os.getenv("BASE_URL", "http://localhost:8000")

@router.get("/prospects")
def root() -> dict:
"""Return a placeholder message for prospects endpoint."""
meta = make_meta("success", "Prospects placeholder")
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

base_url is read at import time, while make_meta() reads BASE_URL at request time. This can lead to inconsistent URLs between meta.base_url and the data.init link (and can also produce double slashes if BASE_URL ends with /). Consider deriving the init link from meta["base_url"] and normalizing with rstrip("/") before concatenating the path.

Suggested change
meta = make_meta("success", "Prospects placeholder")
meta = make_meta("success", "Prospects placeholder")
base_url = meta.get("base_url", "").rstrip("/") # Derive from meta to keep URLs consistent

Copilot uses AI. Check for mistakes.
data = {"message": "This is a placeholder for the /prospects endpoint."}
data = {"init": f"{base_url}/prospects/init"}
return {"meta": meta, "data": data}


Expand All @@ -38,24 +39,30 @@ def prospects_init() -> dict:
# Get unique titles and their counts (column is 'title')
cur.execute('SELECT title, COUNT(*) FROM prospects WHERE title IS NOT NULL GROUP BY title ORDER BY COUNT(*) DESC;')
title_rows = cur.fetchall()
def slugify(text):
import re
text = str(text).lower()
text = re.sub(r'[^a-z0-9]+', '-', text)
return text.strip('-')
Comment on lines +42 to +46
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

Defining slugify() inside the request handler (and importing re inside the helper) adds per-request overhead and makes the helper harder to reuse/test. Consider moving slugify (and the re import) to module scope, outside the try: block.

Copilot uses AI. Check for mistakes.

title = [
{"label": t[0], "count": t[1]} for t in title_rows if t[0] is not None
{"label": f"{t[0]} ({t[1]})", "value": slugify(t[0])} for t in title_rows if t[0] is not None
]
total_unique_title = len(title)

# Get unique seniority and their counts (column is 'seniority')
cur.execute('SELECT seniority, COUNT(*) FROM prospects WHERE seniority IS NOT NULL GROUP BY seniority ORDER BY COUNT(*) DESC;')
seniority_rows = cur.fetchall()
seniority = [
{"label": s[0], "count": s[1]} for s in seniority_rows if s[0] is not None
{"label": f"{s[0]} ({s[1]})", "value": slugify(s[0])} for s in seniority_rows if s[0] is not None
]
total_unique_seniority = len(seniority)

# Get unique sub_departments and their counts (column is 'sub_departments')
cur.execute('SELECT sub_departments, COUNT(*) FROM prospects WHERE sub_departments IS NOT NULL GROUP BY sub_departments ORDER BY COUNT(*) DESC;')
sub_department_rows = cur.fetchall()
sub_departments = [
{"label": sd[0], "count": sd[1]} for sd in sub_department_rows if sd[0] is not None
{"label": f"{sd[0]} ({sd[1]})", "value": slugify(sd[0])} for sd in sub_department_rows if sd[0] is not None
]
total_unique_sub_departments = len(sub_departments)
except Exception:
Expand All @@ -73,15 +80,15 @@ def prospects_init() -> dict:
"total_prospects": total,
"title": {
"total_unique": total_unique_title,
"values": title
"values": title[:3]
},
"seniority": {
"total_unique": total_unique_seniority,
"values": seniority
"values": seniority[:3]
},
"departments": {
"total_unique": total_unique_sub_departments,
"values": sub_departments
"values": sub_departments[:3]
Comment on lines +83 to +91
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

The response now slices to the top 3 values, but the queries still fetch all grouped rows (fetchall()), which can be expensive with many distinct titles/seniority/departments. Consider using LIMIT 3 for the top lists and a separate COUNT(DISTINCT ...) query for total_unique to avoid transferring/processing large result sets.

Copilot uses AI. Check for mistakes.
}
}
return {"meta": meta, "data": data}
Loading