Skip to content

fix(api,web): debounce account search and cache service token (REGBACKLOG-445) - #1950

Open
jimmypalelil wants to merge 1 commit into
bcgov:mainfrom
jimmypalelil:regbacklog_445
Open

jimmypalelil wants to merge 1 commit into
bcgov:mainfrom
jimmypalelil:regbacklog_445

Conversation

@jimmypalelil

@jimmypalelil jimmypalelil commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Issue:

Description of changes:

  • strr-host-pm-web (1.3.39):
    • Increase account name search debounce from 150ms to 450ms in app/pages/auth/account/create-new.vue.
    • Enforce a minimum 3-character threshold (trimmedName.length < 3) before querying GET /accounts/search, resetting accountExists / loading state and revalidating silently when shorter.
    • Cancel in-flight /accounts/search requests using AbortController on subsequent keystrokes, before new requests, and on scope dispose, ignoring AbortError responses.
    • Add unit tests in tests/unit/create-new-account-page.spec.ts covering minimum length, debounce timing, and in-flight request cancellation.
    • Add Playwright E2E test in tests/e2e/create-new-account.test.ts covering minimum length, debounced typing, existing/unique account validation, and dropping below 3 characters (kept separate from tests/e2e/smoke-tests/Scenario-*.test.ts since existing smoke specs fail at import time on a removed i18nText.rentalUnitSetupType key), and fix the BCSC TOS locator visibility check in tests/e2e/test-utils/auth-setup.ts.
  • strr-api (0.3.47):
    • Cache Keycloak service client tokens in AuthService._token_cache (cachelib.SimpleCache) keyed by client credentials/token URL with a safety buffer (ttl - min(30, ttl // 5)) and skip caching when expires_in <= 0.
    • Remove leftover print(token) debug statement in AuthService.search_accounts.
    • Declare cachelib = "^0.13.0" directly in pyproject.toml and update poetry.lock.
    • Add unit tests in tests/unit/services/test_auth_service.py covering token caching within TTL, near-expiry refresh, and zero-TTL handling.

How this was tested:

  • Unit / integration tests run:
    • strr-host-pm-web unit tests: pnpm vitest run --dir tests/unit — 24 test files, 346 tests passed; pnpm lint — passed.
    • strr-host-pm-web E2E test: npx playwright test tests/e2e/create-new-account.test.ts against local nuxt dev (http://localhost:3000) + local strr-api (http://127.0.0.1:8000) — 1 passed (11.6s); npx eslint — passed.
    • strr-api unit tests & linters: pytest tests/unit/services/test_auth_service.py --no-cov — 16 passed; black --check, isort --check, pylint src/strr_api/services/auth_service.py (10.00/10), and poetry check — passed.
  • Manual / local / DB verification:
    • Ran local strr-api (gunicorn on 127.0.0.1:8000, connected to dev Keycloak & Auth API) and benchmarked AuthService.get_service_client_token() and GET /accounts/search?name=Strr (10 requests, all 200 OK):
      • Token fetch (get_service_client_token): cold 93.95ms → warm cached 0.0022ms (median)
      • HTTP GET /accounts/search: cold (1st request) 763.81ms → warm (requests 2–10) p50 = 339.67ms (min 332.67ms, max 351.95ms) — 55.5% latency reduction (~424ms saved per request).

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the BC Registry and Digital Services BSD 3-Clause License

@bcregistry-sre

Copy link
Copy Markdown
Collaborator

Temporary Url for review: https://strr-hosts-dev--pr-1950-xxpr4z2k.web.app

@bcregistry-sre

Copy link
Copy Markdown
Collaborator

Temporary Url for review: https://strr-hosts-dev--pr-1950-xxpr4z2k.web.app

@severinbeauvais

severinbeauvais commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator
  • since existing smoke specs fail at import time on a removed i18nText.rentalUnitSetupType key

Is there a ticket for this? Otherwise those tests stay broken without anyone noticing.

"private": true,
"type": "module",
"version": "1.3.38",
"version": "1.3.39",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

#1939 and #1943 also bump host to 1.3.39, so whichever merges later will need another bump

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feel free to resolve this conversation if you're not concerned about this.

"""Ensure service client token cache is isolated per test."""
AuthService._token_cache.clear()
yield
AuthService._token_cache.clear()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Clever way to clear before and after each test 👍

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feel free to resolve this conversation, haha.

@bcregistry-sre

Copy link
Copy Markdown
Collaborator

Temporary Url for review: https://strr-hosts-dev--pr-1950-xxpr4z2k.web.app

@bcregistry-sre

Copy link
Copy Markdown
Collaborator

Temporary Url for review: https://strr-hosts-dev--pr-1950-xxpr4z2k.web.app

@severinbeauvais severinbeauvais left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm happy with this when you're happy with this.

@sonarqubecloud

Copy link
Copy Markdown

@bcregistry-sre

Copy link
Copy Markdown
Collaborator

Temporary Url for review: https://strr-hosts-dev--pr-1950-xxpr4z2k.web.app

This branch has not been deployed

No deployments
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.

3 participants