Skip to content

Conversation

@marcoacierno
Copy link
Member

Display a boolean flag in the Grant admin change list view that indicates whether a request for an invitation letter has been submitted. This helps administrators quickly identify which grants have associated invitation letter requests.

Changes:

  • Added has_invitation_letter_request() method to Grant model
  • Added has_invitation_letter_request_flag display method to GrantAdmin
  • Added flag to admin list_display with 📧 emoji icon

Fixes #4384

Generated with Claude Code

Display a boolean flag in the Grant admin change list view that indicates
whether a request for an invitation letter has been submitted. This helps
administrators quickly identify which grants have associated invitation
letter requests.

Changes:
- Added has_invitation_letter_request() method to Grant model
- Added has_invitation_letter_request_flag display method to GrantAdmin
- Added flag to admin list_display with 📧 emoji icon

Fixes #4384

Co-authored-by: Marco Acierno <[email protected]>
@vercel
Copy link

vercel bot commented Aug 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
pycon Ready Ready Preview Aug 17, 2025 2:03pm

return False

from visa.models import InvitationLetterRequest
return InvitationLetterRequest.objects.filter(
Copy link
Member Author

Choose a reason for hiding this comment

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

@claude This would cause a N+1 in the admin page. I think we use Django's annotate to fetch if the invitation letter exists or not in the django admin query instead of this method

Copy link
Contributor

@claude claude bot Aug 12, 2025

Choose a reason for hiding this comment

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

Claude finished @marcoacierno's task —— View job


N+1 Query Issue Fixed ✅

You're absolutely right about the N+1 issue! I've optimized the implementation using Django's Exists() annotation.

Todo List:

  • Read repository guidelines (CLAUDE.md)
  • Examine current implementation
  • Find invitation letter model relationship
  • Implement queryset annotation in GrantAdmin
  • Update/remove the model method
  • Test the optimization
  • Commit and push changes

Changes Made:

  1. Added annotation to GrantAdmin.get_queryset():

    • Uses Exists() with InvitationLetterRequest.objects.filter() to check for invitation letter requests
    • This performs a single SQL query with an EXISTS subquery instead of N individual queries
  2. Updated has_invitation_letter_request_flag() method:

    • Now uses getattr(obj, 'has_invitation_letter_request', False) to access the annotated field
    • No longer calls the model method that would trigger individual queries
  3. Removed the has_invitation_letter_request() method from Grant model:

    • This method is no longer needed since we're using annotation
    • Eliminates the source of the N+1 queries

Performance Impact:

  • Before: 1 query to load grants + N queries for invitation letter checks = N+1 queries
  • After: 1 query with EXISTS subquery = 1 query total

The optimization follows the same pattern already used for is_proposed_speaker, is_confirmed_speaker, and has_voucher annotations in the same admin class.

Use Django''s Exists annotation in get_queryset() instead of calling
has_invitation_letter_request() method for each grant in the admin list.
This optimizes the query to use a single SQL query with EXISTS subquery
rather than individual queries for each grant row.

Co-authored-by: Marco Acierno <[email protected]>
@codecov
Copy link

codecov bot commented Aug 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.53%. Comparing base (7efdfad) to head (4ebf190).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4468   +/-   ##
=======================================
  Coverage   94.53%   94.53%           
=======================================
  Files         352      352           
  Lines       10131    10131           
  Branches      733      733           
=======================================
  Hits         9577     9577           
  Misses        461      461           
  Partials       93       93           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@marcoacierno marcoacierno marked this pull request as ready for review August 14, 2025 04:22
Copy link
Member

@estyxx estyxx left a comment

Choose a reason for hiding this comment

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

LGTM! 🙏

@marcoacierno marcoacierno merged commit 86ef6f5 into main Aug 17, 2025
5 of 6 checks passed
@marcoacierno marcoacierno deleted the claude/issue-4384-20250806-1655 branch August 17, 2025 14:00
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.

Display Invitation Letter Request flag in Grant Admin

3 participants