[v1.38.x] Send less requests to scratch.mit.edu/session etc. - #7666
Merged
WorldLanguages merged 15 commits intoJul 23, 2024
Conversation
WorldLanguages
commented
Jul 20, 2024
This was referenced Jul 20, 2024
Samq64
approved these changes
Jul 21, 2024
Samq64
left a comment
Member
There was a problem hiding this comment.
I don't have a new Scratcher to test the 120 second rule.
WorldLanguages
added a commit
to WorldLanguages/ScratchAddons
that referenced
this pull request
Jul 28, 2024
…chAddons#7666) * Initial commit * Format code * Fix TODO: handle chrome.storage.session undefined * Remove invalid TODO * Remove console.log * Background: only use cache on first time * Revert canUseCachedSession * exact-count addon changes (profiles) * Change animated-thumb later * Only call refreshFn once * Use underscore for _requestFetchFn attr * Remove outdated comment * Do not reference isScratchGui variable * Add code comment * Fix execution order --------- Co-authored-by: WorldLanguages <WorldLanguages@users.noreply.github.com>
WorldLanguages
added a commit
that referenced
this pull request
Jul 31, 2024
…7650) * [v1.38.x] Stop fetching scratch.mit.edu/csrf_token and more optimizations (#7647) * Use getAllCookieStores() instead of fetching hack * Call background alarms less often (`msg-count-badge` affected) (#7505) * Remove unnecessary `cleanCsInfoCache` alarm * Fetch messages less often if user inactive * Format code --------- Co-authored-by: WorldLanguages <WorldLanguages@users.noreply.github.com> * Popup doesn't really need to refetch cookies --------- Co-authored-by: WorldLanguages <WorldLanguages@users.noreply.github.com> * Set value of `scratchAddons.cookieStoreId` * Format code * [v1.38.x] Send less requests to `scratch.mit.edu/session` etc. (#7666) * Initial commit * Format code * Fix TODO: handle chrome.storage.session undefined * Remove invalid TODO * Remove console.log * Background: only use cache on first time * Revert canUseCachedSession * exact-count addon changes (profiles) * Change animated-thumb later * Only call refreshFn once * Use underscore for _requestFetchFn attr * Remove outdated comment * Do not reference isScratchGui variable * Add code comment * Fix execution order --------- Co-authored-by: WorldLanguages <WorldLanguages@users.noreply.github.com> --------- Co-authored-by: WorldLanguages <WorldLanguages@users.noreply.github.com>
Member
Author
|
Regression: #7744 |
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.
Resolves comment #7651 (comment)
Related: #7648
When viewing the diff, I recommend you enable "hide whitespace".
Changes
This PR intends to make very small changes/optimizations to reduce the load on Scratch servers. It should also slightly help with battery and data usage.
These are small code changes. Big restructurings are intentionally not made.
The changes are made in such a way that anyone can clearly see that, after the changes, it's impossible that the extension sends more than requests than before.
Background process (service worker / event page)
The amount of requests to
/sessionwill decrease significantly. This is strongly related to the Manifest V3 lifecycle and usingchrome.storage.sessionto cache data./sessionwould be fetched each time the service worker wakes up./sessionis cached throughchrome.storage.sessionand the amount of background requests to that endpoint should be similar to our old Manifest V2 versions.addToQueue) remains intentionally unchanged. It may still request/sessionif Scratch cookies changed.Non-addon code running in Scratch tabs (content scripts in both worlds)
The amount of requests to
/sessionwill decrease significantly.scratch-wwwpages, such as the front page, projects, and studios, we don't need to fetch/sessionourselves on page load, as Scratch will do this automatically. We can obtain the response data either by polluting XHR or by looking at Redux. (In this PR I fetch XHR as it's the easiest and more reliable option).addon.auth.fetchX(X can be "Username", "IsLoggedIn", "UserId" or "XToken") there is no need to fetch/session. In fact, in non-www pages (that is, "scratchr2" pages) no requests to/sessionwill be sent at all, until one of the running userscripts calls one of these methods./sessionmore than once. Only in some www pages the user can log in or out without a reload. This may mean data gets out of sync if the user logs in to a different account, but that's what already happens on vanilla Scratch, and what tricks like "follow yourself" rely on.Addons
forum-post-countdownaddon reuses the session data fetched by theisLoggedIn()call, so overall 1 request is sent instead of two.exact-count: Do not fetch exact project count if it does not exceed 100. Do not fetch exact favorites and studio counts. (May revert this last decision if there's user feedback about it, see issueexact-count: rethink exact counts for profiles #7623)Extension popup
No changes
Tests
Have to test