[web] update the projects lastUpdated timestamp when changing file-tree (#24867)

* [misc] freeze time before any other unit test setup steps

Freezing it after other work (notably sandboxed-module imports) will
result in flaky tests.

* [web] update the projects lastUpdated timestamp when changing file-tree

GitOrigin-RevId: b82b2ff74dc31886f3c4bd300375117eead6e0cd
This commit is contained in:
Jakob Ackermann
2025-04-16 08:05:14 +00:00
committed by Copybot
parent 8b3f90b2c1
commit 2825083ec8
21 changed files with 357 additions and 165 deletions
+4 -2
View File
@@ -136,7 +136,8 @@ async function createRecoveryFolder(projectId) {
const recoveryFolder = `recovered-${Date.now()}`
const { folder } = await ProjectEntityMongoUpdateHandler.promises.mkdirp(
new ObjectId(projectId),
recoveryFolder
recoveryFolder,
null // unset lastUpdatedBy
)
console.log('Created recovery folder:', folder._id.toString())
return folder
@@ -149,7 +150,8 @@ async function restoreMissingDocs(projectId, folder, missingDocs) {
await ProjectEntityMongoUpdateHandler.promises.addDoc(
new ObjectId(projectId),
folder._id,
doc
doc,
null // unset lastUpdatedBy
)
console.log('Restored doc to filetree:', doc._id.toString())
} catch (err) {
@@ -104,7 +104,8 @@ async function deleteDoc(projectId, docId) {
await ProjectEntityMongoUpdateHandler.promises.deleteEntity(
projectId,
docId,
'doc'
'doc',
null // unset lastUpdatedBy
)
}
}
@@ -115,7 +116,8 @@ async function deleteFile(projectId, fileId) {
await ProjectEntityMongoUpdateHandler.promises.deleteEntity(
projectId,
fileId,
'file'
'file',
null // unset lastUpdatedBy
)
}
}
@@ -17,6 +17,7 @@ import fs from 'node:fs'
import logger from '@overleaf/logger'
const { ObjectId } = mongodb
const lastUpdated = new Date()
const argv = minimist(process.argv.slice(2), {
string: ['logs'],
@@ -157,6 +158,8 @@ async function fixRootFolder(projectId) {
fileRefs: [],
},
],
lastUpdated,
lastUpdatedBy: null, // unset lastUpdatedBy
},
}
)
@@ -185,6 +188,10 @@ async function removeNulls(projectId, _id) {
[`${path}.docs`]: null,
[`${path}.fileRefs`]: null,
},
$set: {
lastUpdated,
lastUpdatedBy: null, // unset lastUpdatedBy
},
}
)
return result.modifiedCount
@@ -196,7 +203,7 @@ async function removeNulls(projectId, _id) {
async function fixArray(projectId, path) {
const result = await db.projects.updateOne(
{ _id: new ObjectId(projectId), [path]: { $not: { $type: 'array' } } },
{ $set: { [path]: [] } }
{ $set: { [path]: [], lastUpdated, lastUpdatedBy: null } }
)
return result.modifiedCount
}
@@ -207,7 +214,13 @@ async function fixArray(projectId, path) {
async function fixFolderId(projectId, path) {
const result = await db.projects.updateOne(
{ _id: new ObjectId(projectId), [path]: { $exists: false } },
{ $set: { [path]: new ObjectId() } }
{
$set: {
[path]: new ObjectId(),
lastUpdated,
lastUpdatedBy: null, // unset lastUpdatedBy
},
}
)
return result.modifiedCount
}
@@ -218,7 +231,13 @@ async function fixFolderId(projectId, path) {
async function removeElementsWithoutIds(projectId, path) {
const result = await db.projects.updateOne(
{ _id: new ObjectId(projectId), [path]: { $type: 'array' } },
{ $pull: { [path]: { _id: null } } }
{
$pull: { [path]: { _id: null } },
$set: {
lastUpdated,
lastUpdatedBy: null, // unset lastUpdatedBy
},
}
)
return result.modifiedCount
}
@@ -245,7 +264,13 @@ async function fixName(projectId, _id) {
const pathToName = `${path}.name`
const result = await db.projects.updateOne(
{ _id: new ObjectId(projectId), [pathToName]: { $in: [null, ''] } },
{ $set: { [pathToName]: name } }
{
$set: {
[pathToName]: name,
lastUpdated,
lastUpdatedBy: null, // unset lastUpdatedBy
},
}
)
return result.modifiedCount
}
+2 -1
View File
@@ -76,7 +76,8 @@ async function processDoc(projectId, docId) {
await ProjectEntityMongoUpdateHandler.promises.replaceDocWithFile(
new ObjectId(projectId),
new ObjectId(docId),
fileRef
fileRef,
null // unset lastUpdatedBy
)
await deleteDocFromMongo(projectId, doc)
await deleteDocFromRedis(projectId, docId)