Skip to content
Open
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
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@
## 2025-02-13 - API Route Prefix Consistency
**Learning:** Inconsistent application of `/api` prefixes between `main.py` router mounting and test suite request paths can lead to 404 errors during testing, even if the logic is correct. This is especially prevalent when multiple agents work on the same codebase with different assumptions about global prefixes.
**Action:** Always verify that `app.include_router` in `backend/main.py` uses `prefix="/api"` if the test suite (e.g., `tests/test_blockchain.py`) expects it. If a router is mounted without a prefix, ensure tests are updated or the prefix is added to `main.py` to maintain repository-wide consistency.

## 2026-02-15 - Pydantic Serialization Overhead
**Learning:** Instantiating Pydantic models in high-volume loops only to call `.model_dump(mode='json')` immediately after adds significant and unnecessary performance overhead (approx. 4x slower than native dictionaries) because it forces data through validation and re-serialization pipelines before final `json.dumps()`.
**Action:** When preparing JSON payloads for caching or returning `Response(content=...)`, construct raw standard Python dictionaries directly rather than using intermediate Pydantic models.
13 changes: 7 additions & 6 deletions backend/routers/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,13 @@ def get_leaderboard(db: Session = Depends(get_db)):
except Exception:
masked_email = "User***"

leaderboard_data.append(LeaderboardEntry(
user_email=masked_email,
reports_count=count,
total_upvotes=upvotes or 0,
rank=idx + 1
).model_dump(mode='json'))
# Construct dictionary directly to bypass Pydantic model validation/serialization overhead
leaderboard_data.append({
"user_email": masked_email,
"reports_count": count,
"total_upvotes": upvotes or 0,
"rank": idx + 1
})

response_data = {"leaderboard": leaderboard_data}
json_data = json.dumps(response_data)
Expand Down
Loading