mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
[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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user