diff --git a/models/accessibilitySettings.js b/models/accessibilitySettings.js index 901cca79d..b9785bb5a 100644 --- a/models/accessibilitySettings.js +++ b/models/accessibilitySettings.js @@ -53,8 +53,8 @@ AccessibilitySettings.allow({ }); if (Meteor.isServer) { - Meteor.startup(() => { - AccessibilitySettings._collection.createIndex({ modifiedAt: -1 }); + Meteor.startup(async () => { + await AccessibilitySettings._collection.createIndexAsync({ modifiedAt: -1 }); const accessibilitySetting = AccessibilitySettings.findOne({}); if (!accessibilitySetting) { AccessibilitySettings.insert({ enabled: false, sort: 0 }); diff --git a/models/accountSettings.js b/models/accountSettings.js index 0ab9d11a8..6b5a6b246 100644 --- a/models/accountSettings.js +++ b/models/accountSettings.js @@ -52,8 +52,8 @@ AccountSettings.allow({ }); if (Meteor.isServer) { - Meteor.startup(() => { - AccountSettings._collection.createIndex({ modifiedAt: -1 }); + Meteor.startup(async () => { + await AccountSettings._collection.createIndexAsync({ modifiedAt: -1 }); AccountSettings.upsert( { _id: 'accounts-allowEmailChange' }, { diff --git a/models/actions.js b/models/actions.js index cb79181e6..b7c946318 100644 --- a/models/actions.js +++ b/models/actions.js @@ -32,8 +32,8 @@ Actions.helpers({ }); if (Meteor.isServer) { - Meteor.startup(() => { - Actions._collection.createIndex({ modifiedAt: -1 }); + Meteor.startup(async () => { + await Actions._collection.createIndexAsync({ modifiedAt: -1 }); }); } diff --git a/models/activities.js b/models/activities.js index 7e3d0a22a..e3080c1da 100644 --- a/models/activities.js +++ b/models/activities.js @@ -83,20 +83,20 @@ if (Meteor.isServer) { // For efficiency create indexes on the date of creation, and on the date of // creation in conjunction with the card or board id, as corresponding views // are largely used in the App. See #524. - Meteor.startup(() => { - Activities._collection.createIndex({ createdAt: -1 }); - Activities._collection.createIndex({ modifiedAt: -1 }); - Activities._collection.createIndex({ cardId: 1, createdAt: -1 }); - Activities._collection.createIndex({ boardId: 1, createdAt: -1 }); - Activities._collection.createIndex( + Meteor.startup(async () => { + await Activities._collection.createIndexAsync({ createdAt: -1 }); + await Activities._collection.createIndexAsync({ modifiedAt: -1 }); + await Activities._collection.createIndexAsync({ cardId: 1, createdAt: -1 }); + await Activities._collection.createIndexAsync({ boardId: 1, createdAt: -1 }); + await Activities._collection.createIndexAsync( { commentId: 1 }, { partialFilterExpression: { commentId: { $exists: true } } }, ); - Activities._collection.createIndex( + await Activities._collection.createIndexAsync( { attachmentId: 1 }, { partialFilterExpression: { attachmentId: { $exists: true } } }, ); - Activities._collection.createIndex( + await Activities._collection.createIndexAsync( { customFieldId: 1 }, { partialFilterExpression: { customFieldId: { $exists: true } } }, ); diff --git a/models/announcements.js b/models/announcements.js index 5458cd70b..b44f7a229 100644 --- a/models/announcements.js +++ b/models/announcements.js @@ -57,8 +57,8 @@ Announcements.allow({ }); if (Meteor.isServer) { - Meteor.startup(() => { - Announcements._collection.createIndex({ modifiedAt: -1 }); + Meteor.startup(async () => { + await Announcements._collection.createIndexAsync({ modifiedAt: -1 }); const announcements = Announcements.findOne({}); if (!announcements) { Announcements.insert({ enabled: false, sort: 0 }); diff --git a/models/attachments.js b/models/attachments.js index 82ad8fcbe..edac1dacc 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -367,8 +367,8 @@ if (Meteor.isServer) { }, }); - Meteor.startup(() => { - Attachments.collection.createIndex({ 'meta.cardId': 1 }); + Meteor.startup(async () => { + await Attachments.collection.createIndexAsync({ 'meta.cardId': 1 }); const storagePath = fileStoreStrategyFactory.storagePath; if (!fs.existsSync(storagePath)) { console.log("create storagePath because it doesn't exist: " + storagePath); diff --git a/models/boards.js b/models/boards.js index 56f21f37d..36be2b79b 100644 --- a/models/boards.js +++ b/models/boards.js @@ -2088,16 +2088,16 @@ Boards.before.insert((userId, doc) => { if (Meteor.isServer) { // Let MongoDB ensure that a member is not included twice in the same board - Meteor.startup(() => { - Boards._collection.createIndex({ modifiedAt: -1 }); - Boards._collection.createIndex( + Meteor.startup(async () => { + await Boards._collection.createIndexAsync({ modifiedAt: -1 }); + await Boards._collection.createIndexAsync( { _id: 1, 'members.userId': 1, }, { unique: true }, ); - Boards._collection.createIndex({ 'members.userId': 1 }); + await Boards._collection.createIndexAsync({ 'members.userId': 1 }); }); // Genesis: the first activity of the newly created board diff --git a/models/cardCommentReactions.js b/models/cardCommentReactions.js index 5e9e23251..6ddd930fa 100644 --- a/models/cardCommentReactions.js +++ b/models/cardCommentReactions.js @@ -64,7 +64,7 @@ CardCommentReactions.allow({ if (Meteor.isServer) { - Meteor.startup(() => { - CardCommentReactions._collection.createIndex({ cardCommentId: 1 }, { unique: true }); + Meteor.startup(async () => { + await CardCommentReactions._collection.createIndexAsync({ cardCommentId: 1 }, { unique: true }); }); } diff --git a/models/cardComments.js b/models/cardComments.js index 7cdf52b5d..fd2e8502d 100644 --- a/models/cardComments.js +++ b/models/cardComments.js @@ -192,9 +192,9 @@ CardComments.textSearch = (userId, textArray) => { if (Meteor.isServer) { // Comments are often fetched within a card, so we create an index to make these // queries more efficient. - Meteor.startup(() => { - CardComments._collection.createIndex({ modifiedAt: -1 }); - CardComments._collection.createIndex({ cardId: 1, createdAt: -1 }); + Meteor.startup(async () => { + await CardComments._collection.createIndexAsync({ modifiedAt: -1 }); + await CardComments._collection.createIndexAsync({ cardId: 1, createdAt: -1 }); }); CardComments.after.insert((userId, doc) => { diff --git a/models/cards.js b/models/cards.js index 66a3e3fac..fc80797e4 100644 --- a/models/cards.js +++ b/models/cards.js @@ -3477,15 +3477,15 @@ if (Meteor.isServer) { }); // Cards are often fetched within a board, so we create an index to make these // queries more efficient. - Meteor.startup(() => { - Cards._collection.createIndex({ modifiedAt: -1 }); - Cards._collection.createIndex({ boardId: 1, createdAt: -1 }); + Meteor.startup(async () => { + await Cards._collection.createIndexAsync({ modifiedAt: -1 }); + await Cards._collection.createIndexAsync({ boardId: 1, createdAt: -1 }); // https://github.com/wekan/wekan/issues/1863 // Swimlane added a new field in the cards collection of mongodb named parentId. // When loading a board, mongodb is searching for every cards, the id of the parent (in the swinglanes collection). // With a huge database, this result in a very slow app and high CPU on the mongodb side. // To correct it, add Index to parentId: - Cards._collection.createIndex({ parentId: 1 }); + await Cards._collection.createIndexAsync({ parentId: 1 }); // let notifydays = parseInt(process.env.NOTIFY_DUE_DAYS_BEFORE_AND_AFTER) || 2; // default as 2 days b4 and after // let notifyitvl = parseInt(process.env.NOTIFY_DUE_AT_HOUR_OF_DAY) || 3600 * 24 * 1e3; // default interval as one day // Meteor.call("findDueCards",notifydays,notifyitvl); diff --git a/models/checklistItems.js b/models/checklistItems.js index db2aa55bd..85c187fcb 100644 --- a/models/checklistItems.js +++ b/models/checklistItems.js @@ -217,10 +217,10 @@ function publishChekListUncompleted(userId, doc) { // Activities if (Meteor.isServer) { - Meteor.startup(() => { - ChecklistItems._collection.createIndex({ modifiedAt: -1 }); - ChecklistItems._collection.createIndex({ checklistId: 1 }); - ChecklistItems._collection.createIndex({ cardId: 1 }); + Meteor.startup(async () => { + await ChecklistItems._collection.createIndexAsync({ modifiedAt: -1 }); + await ChecklistItems._collection.createIndexAsync({ checklistId: 1 }); + await ChecklistItems._collection.createIndexAsync({ cardId: 1 }); }); ChecklistItems.after.update((userId, doc, fieldNames) => { diff --git a/models/checklists.js b/models/checklists.js index 606e58f3f..c2cf6b2ab 100644 --- a/models/checklists.js +++ b/models/checklists.js @@ -286,9 +286,9 @@ if (Meteor.isServer) { }, }); - Meteor.startup(() => { - Checklists._collection.createIndex({ modifiedAt: -1 }); - Checklists._collection.createIndex({ cardId: 1, createdAt: 1 }); + Meteor.startup(async () => { + await Checklists._collection.createIndexAsync({ modifiedAt: -1 }); + await Checklists._collection.createIndexAsync({ cardId: 1, createdAt: 1 }); }); Checklists.after.insert((userId, doc) => { diff --git a/models/customFields.js b/models/customFields.js index 55d4cef98..47dd9921a 100644 --- a/models/customFields.js +++ b/models/customFields.js @@ -232,9 +232,9 @@ function customFieldEdit(userId, doc) { } if (Meteor.isServer) { - Meteor.startup(() => { - CustomFields._collection.createIndex({ modifiedAt: -1 }); - CustomFields._collection.createIndex({ boardIds: 1 }); + Meteor.startup(async () => { + await CustomFields._collection.createIndexAsync({ modifiedAt: -1 }); + await CustomFields._collection.createIndexAsync({ boardIds: 1 }); }); CustomFields.after.insert((userId, doc) => { diff --git a/models/integrations.js b/models/integrations.js index 7075df2c3..3daa3cb8d 100644 --- a/models/integrations.js +++ b/models/integrations.js @@ -122,9 +122,9 @@ Integrations.allow({ //INTEGRATIONS REST API if (Meteor.isServer) { - Meteor.startup(() => { - Integrations._collection.createIndex({ modifiedAt: -1 }); - Integrations._collection.createIndex({ boardId: 1 }); + Meteor.startup(async () => { + await Integrations._collection.createIndexAsync({ modifiedAt: -1 }); + await Integrations._collection.createIndexAsync({ boardId: 1 }); }); /** diff --git a/models/invitationCodes.js b/models/invitationCodes.js index 5563e4aea..31e4b4016 100644 --- a/models/invitationCodes.js +++ b/models/invitationCodes.js @@ -66,8 +66,8 @@ InvitationCodes.helpers({ // }); if (Meteor.isServer) { - Meteor.startup(() => { - InvitationCodes._collection.createIndex({ modifiedAt: -1 }); + Meteor.startup(async () => { + await InvitationCodes._collection.createIndexAsync({ modifiedAt: -1 }); }); Boards.deny({ fetch: ['members'], diff --git a/models/lists.js b/models/lists.js index 4eb4574f1..b13f61a8d 100644 --- a/models/lists.js +++ b/models/lists.js @@ -561,10 +561,10 @@ Meteor.methods({ }); if (Meteor.isServer) { - Meteor.startup(() => { - Lists._collection.rawCollection().createIndex({ modifiedAt: -1 }); - Lists._collection.rawCollection().createIndex({ boardId: 1 }); - Lists._collection.rawCollection().createIndex({ archivedAt: -1 }); + Meteor.startup(async () => { + await Lists._collection.rawCollection().createIndex({ modifiedAt: -1 }); + await Lists._collection.rawCollection().createIndex({ boardId: 1 }); + await Lists._collection.rawCollection().createIndex({ archivedAt: -1 }); }); } diff --git a/models/lockoutSettings.js b/models/lockoutSettings.js index 04bd18cc6..d0f4dfa6e 100644 --- a/models/lockoutSettings.js +++ b/models/lockoutSettings.js @@ -55,8 +55,8 @@ LockoutSettings.allow({ }); if (Meteor.isServer) { - Meteor.startup(() => { - LockoutSettings._collection.createIndex({ modifiedAt: -1 }); + Meteor.startup(async () => { + await LockoutSettings._collection.createIndexAsync({ modifiedAt: -1 }); // Known users settings LockoutSettings.upsert( diff --git a/models/org.js b/models/org.js index 17c0b1981..41bdb47b4 100644 --- a/models/org.js +++ b/models/org.js @@ -292,9 +292,9 @@ if (Meteor.isServer) { if (Meteor.isServer) { // Index for Organization name. - Meteor.startup(() => { - // Org._collection.createIndex({ name: -1 }); - Org._collection.createIndex({ orgDisplayName: 1 }); + Meteor.startup(async () => { + // Org._collection.createIndexAsync({ name: -1 }); + await Org._collection.createIndexAsync({ orgDisplayName: 1 }); }); } diff --git a/models/orgUser.js b/models/orgUser.js index 026cbdbcf..aea757587 100644 --- a/models/orgUser.js +++ b/models/orgUser.js @@ -73,9 +73,9 @@ OrgUser.attachSchema( if (Meteor.isServer) { // Index for Organization User. - Meteor.startup(() => { - OrgUser._collection.createIndex({ orgId: -1 }); - OrgUser._collection.createIndex({ orgId: -1, userId: -1 }); + Meteor.startup(async () => { + await OrgUser._collection.createIndexAsync({ orgId: -1 }); + await OrgUser._collection.createIndexAsync({ orgId: -1, userId: -1 }); }); } diff --git a/models/positionHistory.js b/models/positionHistory.js index a70b9fbab..c741dcdd4 100644 --- a/models/positionHistory.js +++ b/models/positionHistory.js @@ -160,10 +160,10 @@ PositionHistory.helpers({ }); if (Meteor.isServer) { - Meteor.startup(() => { - PositionHistory._collection.createIndex({ boardId: 1, entityType: 1, entityId: 1 }); - PositionHistory._collection.createIndex({ boardId: 1, entityType: 1 }); - PositionHistory._collection.createIndex({ createdAt: -1 }); + Meteor.startup(async () => { + await PositionHistory._collection.createIndexAsync({ boardId: 1, entityType: 1, entityId: 1 }); + await PositionHistory._collection.createIndexAsync({ boardId: 1, entityType: 1 }); + await PositionHistory._collection.createIndexAsync({ createdAt: -1 }); }); } diff --git a/models/rules.js b/models/rules.js index 38b3c87a5..0afb84f7e 100644 --- a/models/rules.js +++ b/models/rules.js @@ -87,8 +87,8 @@ Rules.allow({ }); if (Meteor.isServer) { - Meteor.startup(() => { - Rules._collection.createIndex({ modifiedAt: -1 }); + Meteor.startup(async () => { + await Rules._collection.createIndexAsync({ modifiedAt: -1 }); }); } diff --git a/models/settings.js b/models/settings.js index 8645e2117..00107b8e4 100644 --- a/models/settings.js +++ b/models/settings.js @@ -202,8 +202,8 @@ Settings.allow({ }); if (Meteor.isServer) { - Meteor.startup(() => { - Settings._collection.createIndex({ modifiedAt: -1 }); + Meteor.startup(async () => { + await Settings._collection.createIndexAsync({ modifiedAt: -1 }); const setting = ReactiveCache.getCurrentSetting(); if (!setting) { const now = new Date(); diff --git a/models/swimlanes.js b/models/swimlanes.js index 64dbfe529..e4a789e5c 100644 --- a/models/swimlanes.js +++ b/models/swimlanes.js @@ -378,9 +378,9 @@ Swimlanes.archivedSwimlaneIds = () => { Swimlanes.hookOptions.after.update = { fetchPrevious: false }; if (Meteor.isServer) { - Meteor.startup(() => { - Swimlanes._collection.createIndex({ modifiedAt: -1 }); - Swimlanes._collection.createIndex({ boardId: 1 }); + Meteor.startup(async () => { + await Swimlanes._collection.createIndexAsync({ modifiedAt: -1 }); + await Swimlanes._collection.createIndexAsync({ boardId: 1 }); }); Swimlanes.after.insert((userId, doc) => { diff --git a/models/tableVisibilityModeSettings.js b/models/tableVisibilityModeSettings.js index 3bee121e2..b68cd971b 100644 --- a/models/tableVisibilityModeSettings.js +++ b/models/tableVisibilityModeSettings.js @@ -52,8 +52,8 @@ TableVisibilityModeSettings.allow({ }); if (Meteor.isServer) { - Meteor.startup(() => { - TableVisibilityModeSettings._collection.createIndex({ modifiedAt: -1 }); + Meteor.startup(async () => { + await TableVisibilityModeSettings._collection.createIndexAsync({ modifiedAt: -1 }); TableVisibilityModeSettings.upsert( { _id: 'tableVisibilityMode-allowPrivateOnly' }, { diff --git a/models/team.js b/models/team.js index b39298cd7..57fbf315a 100644 --- a/models/team.js +++ b/models/team.js @@ -259,8 +259,8 @@ if (Meteor.isServer) { if (Meteor.isServer) { // Index for Team name. - Meteor.startup(() => { - Team._collection.createIndex({ teamDisplayName: 1 }); + Meteor.startup(async () => { + await Team._collection.createIndexAsync({ teamDisplayName: 1 }); }); } diff --git a/models/translation.js b/models/translation.js index 4f69829d1..a901c3eeb 100644 --- a/models/translation.js +++ b/models/translation.js @@ -139,8 +139,8 @@ if (Meteor.isServer) { if (Meteor.isServer) { // Index for Organization User. - Meteor.startup(() => { - Translation._collection.createIndex({ modifiedAt: -1 }); + Meteor.startup(async () => { + await Translation._collection.createIndexAsync({ modifiedAt: -1 }); }); } diff --git a/models/triggers.js b/models/triggers.js index 6983955c6..3f49219b3 100644 --- a/models/triggers.js +++ b/models/triggers.js @@ -68,8 +68,8 @@ Triggers.helpers({ }); if (Meteor.isServer) { - Meteor.startup(() => { - Triggers._collection.createIndex({ modifiedAt: -1 }); + Meteor.startup(async () => { + await Triggers._collection.createIndexAsync({ modifiedAt: -1 }); }); } diff --git a/models/unsavedEdits.js b/models/unsavedEdits.js index a74de60d2..71576856b 100644 --- a/models/unsavedEdits.js +++ b/models/unsavedEdits.js @@ -55,9 +55,9 @@ if (Meteor.isServer) { function isAuthor(userId, doc, fieldNames = []) { return userId === doc.userId && fieldNames.indexOf('userId') === -1; } - Meteor.startup(() => { - UnsavedEditCollection._collection.createIndex({ modifiedAt: -1 }); - UnsavedEditCollection._collection.createIndex({ userId: 1 }); + Meteor.startup(async () => { + await UnsavedEditCollection._collection.createIndexAsync({ modifiedAt: -1 }); + await UnsavedEditCollection._collection.createIndexAsync({ userId: 1 }); }); UnsavedEditCollection.allow({ insert: isAuthor, diff --git a/models/userPositionHistory.js b/models/userPositionHistory.js index 373ed232f..8dba36e3e 100644 --- a/models/userPositionHistory.js +++ b/models/userPositionHistory.js @@ -286,12 +286,12 @@ UserPositionHistory.helpers({ }); if (Meteor.isServer) { - Meteor.startup(() => { - UserPositionHistory._collection.createIndex({ userId: 1, boardId: 1, createdAt: -1 }); - UserPositionHistory._collection.createIndex({ userId: 1, entityType: 1, entityId: 1 }); - UserPositionHistory._collection.createIndex({ userId: 1, isCheckpoint: 1 }); - UserPositionHistory._collection.createIndex({ batchId: 1 }); - UserPositionHistory._collection.createIndex({ createdAt: 1 }); // For cleanup of old entries + Meteor.startup(async () => { + await UserPositionHistory._collection.createIndexAsync({ userId: 1, boardId: 1, createdAt: -1 }); + await UserPositionHistory._collection.createIndexAsync({ userId: 1, entityType: 1, entityId: 1 }); + await UserPositionHistory._collection.createIndexAsync({ userId: 1, isCheckpoint: 1 }); + await UserPositionHistory._collection.createIndexAsync({ batchId: 1 }); + await UserPositionHistory._collection.createIndexAsync({ createdAt: 1 }); // For cleanup of old entries }); /** diff --git a/models/users.js b/models/users.js index f61bdb1c0..df7f4a8f9 100644 --- a/models/users.js +++ b/models/users.js @@ -2895,11 +2895,11 @@ const addCronJob = _.debounce( if (Meteor.isServer) { // Let mongoDB ensure username unicity - Meteor.startup(() => { - allowedSortValues.forEach((value) => { - Lists._collection.createIndex(value); - }); - Users._collection.createIndex({ + Meteor.startup(async () => { + for (const value of allowedSortValues) { + await Lists._collection.createIndexAsync(value); + } + await Users._collection.createIndexAsync({ modifiedAt: -1, }); // Avatar URLs from CollectionFS to Meteor-Files, at users collection avatarUrl field: diff --git a/packages/wekan-accounts-sandstorm/server.js b/packages/wekan-accounts-sandstorm/server.js index 032549692..d1f781cb2 100644 --- a/packages/wekan-accounts-sandstorm/server.js +++ b/packages/wekan-accounts-sandstorm/server.js @@ -53,7 +53,9 @@ if (__meteor_runtime_config__.SANDSTORM) { // Maps tokens to currently-waiting login method calls. if (Package["accounts-base"]) { - Meteor.users.createIndex("services.sandstorm.id", {unique: 1, sparse: 1}); + Meteor.startup(async () => { + await Meteor.users.createIndexAsync("services.sandstorm.id", {unique: 1, sparse: 1}); + }); } Meteor.onConnection(function (connection) { diff --git a/server/cronJobStorage.js b/server/cronJobStorage.js index 028198df8..91d4aa079 100644 --- a/server/cronJobStorage.js +++ b/server/cronJobStorage.js @@ -14,28 +14,28 @@ export const CronJobErrors = new Mongo.Collection('cronJobErrors'); // Indexes for performance if (Meteor.isServer) { - Meteor.startup(() => { + Meteor.startup(async () => { // Index for job status queries - CronJobStatus._collection.createIndex({ jobId: 1 }); - CronJobStatus._collection.createIndex({ status: 1 }); - CronJobStatus._collection.createIndex({ createdAt: 1 }); - CronJobStatus._collection.createIndex({ updatedAt: 1 }); - + await CronJobStatus._collection.createIndexAsync({ jobId: 1 }); + await CronJobStatus._collection.createIndexAsync({ status: 1 }); + await CronJobStatus._collection.createIndexAsync({ createdAt: 1 }); + await CronJobStatus._collection.createIndexAsync({ updatedAt: 1 }); + // Index for job steps queries - CronJobSteps._collection.createIndex({ jobId: 1 }); - CronJobSteps._collection.createIndex({ stepIndex: 1 }); - CronJobSteps._collection.createIndex({ status: 1 }); - + await CronJobSteps._collection.createIndexAsync({ jobId: 1 }); + await CronJobSteps._collection.createIndexAsync({ stepIndex: 1 }); + await CronJobSteps._collection.createIndexAsync({ status: 1 }); + // Index for job queue queries - CronJobQueue._collection.createIndex({ priority: 1, createdAt: 1 }); - CronJobQueue._collection.createIndex({ status: 1 }); - CronJobQueue._collection.createIndex({ jobType: 1 }); - + await CronJobQueue._collection.createIndexAsync({ priority: 1, createdAt: 1 }); + await CronJobQueue._collection.createIndexAsync({ status: 1 }); + await CronJobQueue._collection.createIndexAsync({ jobType: 1 }); + // Index for job errors queries - CronJobErrors._collection.createIndex({ jobId: 1, createdAt: -1 }); - CronJobErrors._collection.createIndex({ stepId: 1 }); - CronJobErrors._collection.createIndex({ severity: 1 }); - CronJobErrors._collection.createIndex({ createdAt: -1 }); + await CronJobErrors._collection.createIndexAsync({ jobId: 1, createdAt: -1 }); + await CronJobErrors._collection.createIndexAsync({ stepId: 1 }); + await CronJobErrors._collection.createIndexAsync({ severity: 1 }); + await CronJobErrors._collection.createIndexAsync({ createdAt: -1 }); }); }