Migrate createIndex to createIndexAsync

This commit is contained in:
Harry Adel 2026-01-24 01:55:29 +02:00
parent 60ecddfce4
commit ca2083c858
32 changed files with 112 additions and 110 deletions

View file

@ -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 });

View file

@ -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' },
{

View file

@ -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 });
});
}

View file

@ -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 } } },
);

View file

@ -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 });

View file

@ -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);

View file

@ -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

View file

@ -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 });
});
}

View file

@ -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) => {

View file

@ -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);

View file

@ -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) => {

View file

@ -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) => {

View file

@ -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) => {

View file

@ -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 });
});
/**

View file

@ -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'],

View file

@ -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 });
});
}

View file

@ -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(

View file

@ -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 });
});
}

View file

@ -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 });
});
}

View file

@ -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 });
});
}

View file

@ -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 });
});
}

View file

@ -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();

View file

@ -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) => {

View file

@ -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' },
{

View file

@ -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 });
});
}

View file

@ -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 });
});
}

View file

@ -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 });
});
}

View file

@ -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,

View file

@ -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
});
/**

View file

@ -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: