Explorar el Código

Merge pull request #17671 from overleaf/mj-project-projection

[web] Use projection when fetching project

GitOrigin-RevId: 4c7eb6582dba9ffa81f8d34c4e353faf1dc15c83
Mathias Jakobsen hace 2 años
padre
commit
192c497508

+ 4 - 2
services/web/app/src/Features/History/HistoryManager.js

@@ -3,7 +3,7 @@ const { fetchJson, fetchNothing } = require('@overleaf/fetch-utils')
 const settings = require('@overleaf/settings')
 const settings = require('@overleaf/settings')
 const OError = require('@overleaf/o-error')
 const OError = require('@overleaf/o-error')
 const UserGetter = require('../User/UserGetter')
 const UserGetter = require('../User/UserGetter')
-const { Project } = require('../../models/Project')
+const ProjectGetter = require('../Project/ProjectGetter')
 
 
 async function initializeProject(projectId) {
 async function initializeProject(projectId) {
   const body = await fetchJson(`${settings.apis.project_history.url}/project`, {
   const body = await fetchJson(`${settings.apis.project_history.url}/project`, {
@@ -115,7 +115,9 @@ async function _deleteProjectInFullProjectHistory(historyId) {
  * @returns Promise<object>
  * @returns Promise<object>
  */
  */
 async function getCurrentContent(projectId) {
 async function getCurrentContent(projectId) {
-  const project = await Project.findById(projectId).exec()
+  const project = await ProjectGetter.promises.getProject(projectId, {
+    overleaf: true,
+  })
   const historyId = project?.overleaf?.history?.id
   const historyId = project?.overleaf?.history?.id
   if (!historyId) {
   if (!historyId) {
     throw new OError('project does not have a history id', { projectId })
     throw new OError('project does not have a history id', { projectId })

+ 4 - 4
services/web/test/unit/src/History/HistoryManagerTests.js

@@ -48,9 +48,9 @@ describe('HistoryManager', function () {
       },
       },
     }
     }
 
 
-    this.ProjectModel = {
-      Project: {
-        findById: sinon.stub().returns(sinon.stub().resolves(this.project)),
+    this.ProjectGetter = {
+      promises: {
+        getProject: sinon.stub().resolves(this.project),
       },
       },
     }
     }
 
 
@@ -59,7 +59,7 @@ describe('HistoryManager', function () {
         '@overleaf/fetch-utils': this.FetchUtils,
         '@overleaf/fetch-utils': this.FetchUtils,
         '@overleaf/settings': this.settings,
         '@overleaf/settings': this.settings,
         '../User/UserGetter': this.UserGetter,
         '../User/UserGetter': this.UserGetter,
-        '../../models/Project': this.ProjectModel,
+        '../Project/ProjectGetter': this.ProjectGetter,
       },
       },
     })
     })
   })
   })