Repository navigation
refactor: update string filtering to be case-insensitive for improved search functionality - #7874
Conversation
… search functionality
| response["Content-Disposition"] = 'attachment; filename="data.xlsx"' | ||
| workbook.save(response) | ||
| return response | ||
|
|
There was a problem hiding this comment.
Review of the diff
1. __contains → __icontains (lines 245, 400, 533)
Good change. Case-insensitive search is usually what users expect for a name filter.
icontains uses ILIKE '%...%', which cannot use a normal btree index. If these tables can become large, consider:
- A
pg_trgmGIN index onasker.username/name, or - Using full-text search (
SearchVector) if search is a first-class feature.
Also note: Django's contains already escapes %/_, so no injection risk — just performance.
2. Content-Disposition f-string → plain string (lines 329, 500, 630)
Correct cleanup. The f-string has no placeholders, so removing it is safe and slightly faster/branch-free.
Minor suggestion: since a filename is being hardcoded repeatedly, consider extracting a constant or helper, e.g.:
def _xlsx_response(workbook):
response = HttpResponse(content_type="application/vnd.ms-excel")
response["Content-Disposition"] = 'attachment; filename="data.xlsx"'
workbook.save(response)
return responseThis removes triplicate code and ensures future header changes (e.g. adding RFC 5987 filename*=UTF-8''... for non-ASCII names) only need to happen once.
💡 The MIME type application/vnd.ms-excel is for legacy .xls. Since you're writing .xlsx via openpyxl, the correct type is:
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"3. Added is_resource_filter = False (line ~408)
This aligns the branch with the sibling method at line ~536, where the same workspace_manage branch already sets the flag to False.
✅ Behavioral fix: when the user is a workspace manager, the extra "resource filter" step was previously still applied. Now it's skipped consistently. Confirm that this is intentional — before, managers were likely getting results filtered by _apply_resource_filter(...) even though they had full access, which would silently hide records. If tests exist for manager-scoped listing, they should be updated.
Summary table
| Change | Verdict | Notes |
|---|---|---|
icontains ×3 |
✅ | Add trigram/GIN index if tables grow |
| Drop f-string in header | ✅ | Factor out duplicate into helper |
is_resource_filter = False |
✅ (verify) | Fixes inconsistency with sibling method |
| MIME type | Should be xlsx-specific MIME |
No correctness regressions spotted; the main open questions are the intent of the is_resource_filter change (tests?) and the MIME-type mismatch.
refactor: update string filtering to be case-insensitive for improved search functionality