Files
wekan/server/models/collectionBootstrap.js
T
Lauri Ojansivu e5092c87e8 Move the card_comment_reactions indexes into the collection bootstrap.
server/models/collectionBootstrap.js already owned this collection's index
(the unique cardCommentId one); 03ffb56a5 added a second module for the
same collection. One place per collection: the cardId and boardId indexes
now sit beside the existing one there, and the separate module is gone.
tests/cardCommentReactionsIndexes.test.cjs pins that arrangement.

Thanks to xet7 !
2026-09-11 11:27:17 +03:00

163 lines
5.8 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import AccessibilitySettings from '/models/accessibilitySettings';
import AccountSettings from '/models/accountSettings';
import Announcements from '/models/announcements';
import CardCommentReactions from '/models/cardCommentReactions';
import InvitationCodes from '/models/invitationCodes';
import LockoutSettings from '/models/lockoutSettings';
import OrgUser from '/models/orgUser';
import PositionHistory from '/models/positionHistory';
import Presences from '/models/presences';
import Rules from '/models/rules';
import TableVisibilityModeSettings from '/models/tableVisibilityModeSettings';
import InviteToBoardRolesSettings, {
INVITE_TO_BOARD_ROLES_ID,
INVITE_TO_BOARD_ROLES_DEFAULT,
} from '/models/inviteToBoardRolesSettings';
import Triggers from '/models/triggers';
import UnsavedEditCollection from '/models/unsavedEdits';
import { ensureIndex } from '/server/lib/mongoStartup';
Meteor.startup(async () => {
await ensureIndex(AccessibilitySettings, { modifiedAt: -1 });
if (!(await AccessibilitySettings.findOneAsync({}))) {
await AccessibilitySettings.insertAsync({ enabled: false, sort: 0 });
}
await ensureIndex(AccountSettings, { modifiedAt: -1 });
await AccountSettings.upsertAsync(
{ _id: 'accounts-allowEmailChange' },
{ $setOnInsert: { booleanValue: false, sort: 0 } },
);
await AccountSettings.upsertAsync(
{ _id: 'accounts-allowUserNameChange' },
{ $setOnInsert: { booleanValue: false, sort: 1 } },
);
await AccountSettings.upsertAsync(
{ _id: 'accounts-allowUserDelete' },
{ $setOnInsert: { booleanValue: false, sort: 0 } },
);
await ensureIndex(Announcements, { modifiedAt: -1 });
if (!(await Announcements.findOneAsync({}))) {
await Announcements.insertAsync({ enabled: false, sort: 0 });
}
await ensureIndex(
CardCommentReactions,
{ cardCommentId: 1 },
{ unique: true },
);
// The two ways the app actually READS reactions - the card publication by
// `cardId: { $in: [...all the board's cards] }`, the board publication by
// `boardId` - had no index: a reported MongoDB log (.tools/crash) had 3,397
// full collection scans of this one collection, up to 1.6 s each on slow
// storage, the bulk of that server's "Slow query" lines.
await ensureIndex(CardCommentReactions, { cardId: 1 });
await ensureIndex(CardCommentReactions, { boardId: 1 });
await ensureIndex(InvitationCodes, { modifiedAt: -1 });
await ensureIndex(LockoutSettings, { modifiedAt: -1 });
await LockoutSettings.upsertAsync(
{ _id: 'known-failuresBeforeLockout' },
{
$setOnInsert: {
value: process.env.ACCOUNTS_LOCKOUT_KNOWN_USERS_FAILURES_BEFORE
? parseInt(process.env.ACCOUNTS_LOCKOUT_KNOWN_USERS_FAILURES_BEFORE, 10) : 3,
category: 'known',
sort: 0,
},
},
);
await LockoutSettings.upsertAsync(
{ _id: 'known-lockoutPeriod' },
{
$setOnInsert: {
value: process.env.ACCOUNTS_LOCKOUT_KNOWN_USERS_PERIOD
? parseInt(process.env.ACCOUNTS_LOCKOUT_KNOWN_USERS_PERIOD, 10) : 60,
category: 'known',
sort: 1,
},
},
);
await LockoutSettings.upsertAsync(
{ _id: 'known-failureWindow' },
{
$setOnInsert: {
value: process.env.ACCOUNTS_LOCKOUT_KNOWN_USERS_FAILURE_WINDOW
? parseInt(process.env.ACCOUNTS_LOCKOUT_KNOWN_USERS_FAILURE_WINDOW, 10) : 15,
category: 'known',
sort: 2,
},
},
);
const typoVar = process.env.ACCOUNTS_LOCKOUT_UNKNOWN_USERS_FAILURES_BERORE;
const correctVar = process.env.ACCOUNTS_LOCKOUT_UNKNOWN_USERS_FAILURES_BEFORE;
await LockoutSettings.upsertAsync(
{ _id: 'unknown-failuresBeforeLockout' },
{
$setOnInsert: {
value: (correctVar || typoVar) ? parseInt(correctVar || typoVar, 10) : 3,
category: 'unknown',
sort: 0,
},
},
);
await LockoutSettings.upsertAsync(
{ _id: 'unknown-lockoutPeriod' },
{
$setOnInsert: {
value: process.env.ACCOUNTS_LOCKOUT_UNKNOWN_USERS_LOCKOUT_PERIOD
? parseInt(process.env.ACCOUNTS_LOCKOUT_UNKNOWN_USERS_LOCKOUT_PERIOD, 10) : 60,
category: 'unknown',
sort: 1,
},
},
);
await LockoutSettings.upsertAsync(
{ _id: 'unknown-failureWindow' },
{
$setOnInsert: {
value: process.env.ACCOUNTS_LOCKOUT_UNKNOWN_USERS_FAILURE_WINDOW
? parseInt(process.env.ACCOUNTS_LOCKOUT_UNKNOWN_USERS_FAILURE_WINDOW, 10) : 15,
category: 'unknown',
sort: 2,
},
},
);
await ensureIndex(OrgUser, { orgId: -1 });
await ensureIndex(OrgUser, { orgId: -1, userId: -1 });
await ensureIndex(Presences, { serverId: -1 });
await ensureIndex(PositionHistory, { boardId: 1, entityType: 1, entityId: 1 });
await ensureIndex(PositionHistory, { boardId: 1, entityType: 1 });
await ensureIndex(PositionHistory, { createdAt: -1 });
await ensureIndex(Rules, { modifiedAt: -1 });
await ensureIndex(TableVisibilityModeSettings, { modifiedAt: -1 });
await TableVisibilityModeSettings.upsertAsync(
{ _id: 'tableVisibilityMode-allowPrivateOnly' },
{ $setOnInsert: { booleanValue: false, sort: 0 } },
);
// #4475: off by default, so board creation stays unrestricted unless a
// site admin explicitly turns it on.
await TableVisibilityModeSettings.upsertAsync(
{ _id: 'tableVisibilityMode-boardCreationAdminOnly' },
{ $setOnInsert: { booleanValue: false, sort: 1 } },
);
await ensureIndex(InviteToBoardRolesSettings, { modifiedAt: -1 });
await InviteToBoardRolesSettings.upsertAsync(
{ _id: INVITE_TO_BOARD_ROLES_ID },
{ $setOnInsert: { allowedRoles: INVITE_TO_BOARD_ROLES_DEFAULT, sort: 0 } },
);
await ensureIndex(Triggers, { modifiedAt: -1 });
await ensureIndex(UnsavedEditCollection, { modifiedAt: -1 });
await ensureIndex(UnsavedEditCollection, { userId: 1 });
});