From 2f9fc6e82e6506a25622732c0c4c8982a6bcade4 Mon Sep 17 00:00:00 2001 From: Tim Down <158919+timdown@users.noreply.github.com> Date: Wed, 26 Mar 2025 10:51:32 +0000 Subject: [PATCH] Update inactive project deactivation index (#24444) * Update inactive project deactivation index * Delete index first, otherwise Mongo complains that the index already exists with a different name GitOrigin-RevId: b28a60c0774a77363c4e052ddb64bf68665cccf5 --- .../InactiveData/InactiveProjectManager.js | 3 -- ...20161029_update_inactive_project_index.mjs | 43 +++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 services/web/migrations/20250320161029_update_inactive_project_index.mjs diff --git a/services/web/app/src/Features/InactiveData/InactiveProjectManager.js b/services/web/app/src/Features/InactiveData/InactiveProjectManager.js index cdbcfd888b..818fe70c08 100644 --- a/services/web/app/src/Features/InactiveData/InactiveProjectManager.js +++ b/services/web/app/src/Features/InactiveData/InactiveProjectManager.js @@ -5,7 +5,6 @@ const DocumentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandle const ProjectGetter = require('../Project/ProjectGetter') const ProjectUpdateHandler = require('../Project/ProjectUpdateHandler') const { Project } = require('../../models/Project') -const { ObjectId } = require('mongodb-legacy') const Modules = require('../../infrastructure/Modules') const { READ_PREFERENCE_SECONDARY } = require('../../infrastructure/mongodb') const { callbackifyAll } = require('@overleaf/promise-utils') @@ -62,8 +61,6 @@ const InactiveProjectManager = { projects = await Project.find({ lastOpened: { $not: { $gt: oldProjectDate } }, }) - .where('_id') - .lt(ObjectId.createFromTime(oldProjectDate / 1000)) .where('active') .equals(true) .select('_id') diff --git a/services/web/migrations/20250320161029_update_inactive_project_index.mjs b/services/web/migrations/20250320161029_update_inactive_project_index.mjs new file mode 100644 index 0000000000..423047dbc7 --- /dev/null +++ b/services/web/migrations/20250320161029_update_inactive_project_index.mjs @@ -0,0 +1,43 @@ +/* eslint-disable no-unused-vars */ + +import Helpers from './lib/helpers.mjs' + +const tags = ['server-ce', 'server-pro', 'saas'] + +const oldIndex = { + key: { + lastOpened: 1, + }, + name: 'lastOpened_1', +} + +const newIndex = { + key: { + lastOpened: 1, + }, + name: 'active_true_lastOpened_1', + partialFilterExpression: { active: true }, +} + +const migrate = async client => { + const { db } = client + + await Helpers.dropIndexesFromCollection(db.projects, [oldIndex]) + await Helpers.addIndexesToCollection(db.projects, [newIndex]) +} + +const rollback = async client => { + const { db } = client + + try { + await Helpers.dropIndexesFromCollection(db.projects, [newIndex]) + await Helpers.addIndexesToCollection(db.projects, [oldIndex]) + } catch (err) { + console.error('Something went wrong rolling back the migrations', err) + } +} +export default { + tags, + migrate, + rollback, +}