Skip to content

refactor: update string filtering to be case-insensitive for improved search functionality - #7874

Merged
wxg0103 merged 1 commit into
v3from
pr@v3@refactor_hompage
Nov 12, 2026
Merged

wxg0103 merged 1 commit into
v3from
pr@v3@refactor_hompage

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

refactor: update string filtering to be case-insensitive for improved search functionality

response["Content-Disposition"] = 'attachment; filename="data.xlsx"'
workbook.save(response)
return response

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

⚠️ Potential issue: In PostgreSQL, icontains uses ILIKE '%...%', which cannot use a normal btree index. If these tables can become large, consider:

  • A pg_trgm GIN index on asker.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 response

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

@wxg0103
wxg0103 merged commit 0a5780d into v3 Nov 12, 2026
3 of 4 checks passed
@wxg0103
wxg0103 deleted the pr@v3@refactor_hompage branch November 12, 2026 10:22
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