Repository navigation
Stop asking the server for things nobody needs - #49
Merged
Merged
Conversation
Two sources of requests that buy nothing. 1. The unread counters polled every 60 seconds whether or not anyone was looking. A tab left open overnight sent hundreds of requests for a badge nobody could see, and on a phone that is data and battery too. The timer now runs only while the tab is visible, and fires immediately when it comes back — so the counter is fresher on return than the plain timer left it, not staler. Measured over 150 seconds in the background: 4 requests before, 0 after. 2. GET /api/teachers/me went out three times on a single page load — once from the setup guard, once from the shell for the name in the header, and once from the dashboard for a flag the guard had just fetched. They now share one request. The cache is keyed by the signed-in account, so the next person to sign in gets their own profile even if the sign-out never ran, and it is dropped whenever anything changes the profile. Dashboard 13 → 11 API calls per load, lessons 11 → 9, messages 5 → 4.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I counted the API calls the app makes on each screen load and per minute while idle. Two sources buy nothing.
1. The unread counters polled a tab nobody was looking at
The messages icon and the notifications bell each refresh once a minute. A plain
timerkeeps doing that in a background tab: a tab left open overnight sends hundreds of requests for a badge nobody can see, and on a phone it spends data and battery on the same.Measured over 150 seconds with the tab reporting
hidden:The timer now runs only while the tab is visible. It also fires the moment the tab comes back:
So the counter is actually fresher on return than the old timer left it — before, she could come back to a badge up to a minute stale.
2.
GET /api/teachers/methree times per page loadThree callers, same request, same answer, one page load:
profileSetupGuard→ProfileSetupService.load()isProfileCompleteTeacherShellComponentfullNamefor the headerDashboardComponent→load()againisProfileComplete, which the guard had just fetchedProfileSetupServicealready documents the intent — "נשמר במטמון כאן ולא נשלף בכל ניווט" — butload()always hit the network, so the cache only ever helped the guard.They now share one request, held in
TeacherProfileService. Two things make it safe:Result
Also checked — nothing to fix
/api/lessonsfor a month,/api/students,/api/payments,/api/notifications, a student card), measured against the EF command log.foreachloops flagged by a first scan inPaymentsController,StudentsControllerandTeachersControllerall await outside the loop — not N+1.Testing
npx ng build— clean.npx vitest run— 30 passing (app.spec.tsfails on main too, unrelated).Demo data untouched — the one field edited to test cache invalidation was restored to קטמון and verified in the database.