[web] deduplicate getting the project when loading the editor (#32762)

* [web] enable async local storage on all the endpoints

Co-authored-by: Brian Gough <brian.gough@overleaf.com>

* [web] deduplicate getting the project when loading the editor

Co-authored-by: Brian Gough <brian.gough@overleaf.com>

* [web] use ProjectAccess state for computing analytics segmentation

Co-authored-by: Brian Gough <brian.gough@overleaf.com>

* [web] restore ownership of active flag and deferredTpdsFlushCounter

* [web] add missing await

* [web] update unit tests

* [web] add metrics for project access caching

* [web] add missing test mock

* [web] invalidate async local storage when changing project access

* [web] deduplicate project lookup when checking for token access

* [web] add helper function for getting cached ProjectAccess

* [web] add acceptance test for caching of ProjectAccess

* [web] account for saas-only project access in tests

* Revert "[web] enable async local storage on all the endpoints"

This reverts commit 1b82f3b935040e8cfd180d1f6bf4183a655580e2.

* [web] add async local storage to project endpoints in top-50

* [web] invalidate async local storage for project access from modules

Co-authored-by: Jessica Lawshe <jessica.lawshe@overleaf.com>

---------

Co-authored-by: Brian Gough <brian.gough@overleaf.com>
Co-authored-by: Jessica Lawshe <jessica.lawshe@overleaf.com>
GitOrigin-RevId: 3eea7956b24e6f937dc1c17948681063d4dca3ea
This commit is contained in:
Jakob Ackermann
2026-04-17 08:07:08 +00:00
committed by Copybot
co-authored by Brian Gough Jessica Lawshe
parent 6117feef1b
commit d56477565c
18 changed files with 219 additions and 69 deletions
@@ -539,17 +539,16 @@ const _ProjectController = {
const responses = await pProps({
userValues: userId ? getUserValues(userId) : defaultUserValues(),
project: ProjectGetter.promises.getProject(projectId, {
_id: 1,
name: 1,
active: 1,
deferredTpdsFlushCounter: 1,
lastUpdated: 1,
track_changes: 1,
owner_ref: 1,
brandVariationId: 1,
overleaf: 1,
tokens: 1,
tokenAccessReadAndWrite_refs: 1, // used for link sharing analytics
collaberator_refs: 1, // used for link sharing analytics
pendingEditor_refs: 1, // used for link sharing analytics
reviewer_refs: 1,
}),
userIsMemberOfGroupSubscription: sessionUser
? (async () =>
@@ -559,16 +558,15 @@ const _ProjectController = {
)
).isMember)()
: false,
_flushToTpds:
TpdsProjectFlusher.promises.flushProjectToTpdsIfNeeded(projectId),
_activate:
InactiveProjectManager.promises.reactivateProjectIfRequired(
projectId
),
})
const { project, userValues, userIsMemberOfGroupSubscription } = responses
await Promise.all([
InactiveProjectManager.promises.reactivateProjectIfRequired(project),
TpdsProjectFlusher.promises.flushProjectToTpdsIfNeeded(project),
])
const {
user,
learnedWords,
@@ -705,9 +703,11 @@ const _ProjectController = {
project.owner_ref
)
if (userId) {
const projectAccess =
await CollaboratorsGetter.promises.getProjectAccess(projectId)
const planLimit = ownerFeatures?.collaborators || 0
const namedEditors = project.collaberator_refs?.length || 0
const pendingEditors = project.pendingEditor_refs?.length || 0
const { namedEditors, pendingEditors, tokenEditors } =
projectAccess.getStats()
const exceedAtLimit = planLimit > -1 && namedEditors >= planLimit
let mode = 'edit'
@@ -727,7 +727,7 @@ const _ProjectController = {
projectId: project._id,
namedEditors,
pendingEditors,
tokenEditors: project.tokenAccessReadAndWrite_refs?.length || 0,
tokenEditors,
planLimit,
exceedAtLimit,
}