Merge pull request #29697 from overleaf/ac-td-user-audit-log-index
Add migration to improve index on userAuditLogEntries GitOrigin-RevId: c4a606e1ab7299008baa3b05ac1fb8ca18036fae
This commit is contained in:
@@ -266,6 +266,8 @@ class User {
|
|||||||
|
|
||||||
db.userAuditLogEntries
|
db.userAuditLogEntries
|
||||||
.find({ userId: new ObjectId(this._id) })
|
.find({ userId: new ObjectId(this._id) })
|
||||||
|
// Explicitly sort in ascending chronological order
|
||||||
|
.sort({ timestamp: 1 })
|
||||||
.toArray((error, auditLog) => {
|
.toArray((error, auditLog) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import Helpers from './lib/helpers.mjs'
|
||||||
|
|
||||||
|
const oldIndex = {
|
||||||
|
key: {
|
||||||
|
userId: 1,
|
||||||
|
},
|
||||||
|
name: 'user_id_1',
|
||||||
|
}
|
||||||
|
|
||||||
|
const newIndex = {
|
||||||
|
key: {
|
||||||
|
userId: 1,
|
||||||
|
timestamp: -1,
|
||||||
|
},
|
||||||
|
name: 'userId_1_timestamp_-1',
|
||||||
|
}
|
||||||
|
|
||||||
|
const tags = ['server-ce', 'server-pro', 'saas']
|
||||||
|
|
||||||
|
const migrate = async client => {
|
||||||
|
const { db } = client
|
||||||
|
await Helpers.addIndexesToCollection(db.userAuditLogEntries, [newIndex])
|
||||||
|
await Helpers.dropIndexesFromCollection(db.userAuditLogEntries, [oldIndex])
|
||||||
|
}
|
||||||
|
|
||||||
|
const rollback = async client => {
|
||||||
|
const { db } = client
|
||||||
|
await Helpers.addIndexesToCollection(db.userAuditLogEntries, [oldIndex])
|
||||||
|
await Helpers.dropIndexesFromCollection(db.userAuditLogEntries, [newIndex])
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
tags,
|
||||||
|
migrate,
|
||||||
|
rollback,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user