Skip to content

Redundant Project Data Query #468

@thehabes

Description

@thehabes

Summary

Multiple route handlers load project data twice per request. The first load happens via checkUserAccess() (which internally calls #load()), and the second happens when a utility function like findLayerById(), findPageById(), or ProjectFactory.loadAsUser() internally calls Project.getById() again.

Root Cause

Utility functions always fetch the project internally with no way to accept a pre-loaded project object. When a route handler has already loaded the project for access control, the subsequent utility call duplicates that database query.

Proposed Fix

Add an optional project parameter to utility functions so callers can pass a pre-loaded project when available. Callers without a pre-loaded project continue to work unchanged by omitting the parameter.

Confirmed Double-Fetch Routes (11)

layer/index.js

Method Route Second fetch via
PUT /:layerId findLayerById()Project.getById()

page/index.js

Method Route Second fetch via
PUT /:pageId findPageById()Project.getById()

line/index.js

Method Route Second fetch via
POST / findPageById()Project.getById()
PUT /:lineId findPageById()Project.getById()
PATCH /:lineId/text findPageById()Project.getById()
PATCH /:lineId/bounds findPageById()Project.getById()

project/projectReadRouter.js

Method Route Second fetch via
GET /:id ProjectFactory.loadAsUser()
GET /:id/manifest ProjectFactory.loadAsUser()

project/customMetadataRouter.js

Method Route Second fetch via
GET /:id/custom database.findOne()
POST /:id/custom database.findOne()
PUT /:id/custom database.findOne()

Potential Double-Fetches (5, depends on ProjectFactory internals)

project/projectCopyRouter.js

  • POST /:projectId/copy — via ProjectFactory.copyProject()
  • POST /:projectId/copy-without-annotations — via ProjectFactory.cloneWithoutAnnotations()
  • POST /:projectId/copy-with-group — via ProjectFactory.cloneWithGroup()
  • POST /:projectId/copy-with-customizations — via ProjectFactory.cloneWithCustomizations()

project/projectReadRouter.js

  • GET /:id/deploymentStatus — via ProjectFactory.checkManifestUploadAndDeployment()

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions