[IMPROVE][Performance] Add new database indexes to improve data query performance (#17839)

Co-authored-by: Diego Sampaio <chinello@gmail.com>
pull/17767/head^2
Rodrigo Nascimento 5 years ago committed by GitHub
parent 893bf78263
commit 12c11f230e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/models/server/models/LivechatRooms.js
  2. 3
      app/models/server/models/LivechatVisitors.js
  3. 2
      app/models/server/models/Messages.js
  4. 9
      app/models/server/models/Rooms.js
  5. 1
      app/models/server/models/Sessions.js
  6. 1
      app/models/server/models/Subscriptions.js
  7. 6
      app/models/server/models/_BaseDb.js
  8. 1
      server/startup/migrations/index.js
  9. 28
      server/startup/migrations/v192.js

@ -18,6 +18,7 @@ export class LivechatRooms extends Base {
this.tryEnsureIndex({ 'omnichannel.predictedVisitorAbandonmentAt': 1 }, { sparse: true });
this.tryEnsureIndex({ closedAt: 1 }, { sparse: true });
this.tryEnsureIndex({ servedBy: 1 }, { sparse: true });
this.tryEnsureIndex({ 'v.token': 1 }, { sparse: true });
}
findLivechat(filter = {}, offset = 0, limit = 20) {

@ -8,6 +8,9 @@ import Settings from './Settings';
export class LivechatVisitors extends Base {
constructor() {
super('livechat_visitor');
this.tryEnsureIndex({ token: 1 });
this.tryEnsureIndex({ 'phone.phoneNumber': 1 }, { sparse: true });
}
/**

@ -9,7 +9,7 @@ export class Messages extends Base {
constructor() {
super('message');
this.tryEnsureIndex({ rid: 1, ts: 1 });
this.tryEnsureIndex({ rid: 1, ts: 1, _updatedAt: 1 });
this.tryEnsureIndex({ ts: 1 });
this.tryEnsureIndex({ 'u._id': 1 });
this.tryEnsureIndex({ editedAt: 1 }, { sparse: true });

@ -11,12 +11,15 @@ export class Rooms extends Base {
super(...args);
this.tryEnsureIndex({ name: 1 }, { unique: true, sparse: true });
this.tryEnsureIndex({ default: 1 });
this.tryEnsureIndex({ featured: 1 });
this.tryEnsureIndex({ default: 1 }, { sparse: true });
this.tryEnsureIndex({ featured: 1 }, { sparse: true });
this.tryEnsureIndex({ muted: 1 }, { sparse: true });
this.tryEnsureIndex({ t: 1 });
this.tryEnsureIndex({ 'u._id': 1 });
this.tryEnsureIndex({ 'tokenpass.tokens.token': 1 });
this.tryEnsureIndex({ ts: 1 });
// Tokenpass
this.tryEnsureIndex({ 'tokenpass.tokens.token': 1 }, { sparse: true });
this.tryEnsureIndex({ tokenpass: 1 }, { sparse: true });
// discussions
this.tryEnsureIndex({ prid: 1 }, { sparse: true });
this.tryEnsureIndex({ fname: 1 }, { sparse: true });

@ -376,6 +376,7 @@ export class Sessions extends Base {
this.tryEnsureIndex({ instanceId: 1, sessionId: 1, year: 1, month: 1, day: 1 });
this.tryEnsureIndex({ instanceId: 1, sessionId: 1, userId: 1 });
this.tryEnsureIndex({ instanceId: 1, sessionId: 1 });
this.tryEnsureIndex({ sessionId: 1 });
this.tryEnsureIndex({ year: 1, month: 1, day: 1, type: 1 });
this.tryEnsureIndex({ type: 1 });
this.tryEnsureIndex({ _computedAt: 1 }, { expireAfterSeconds: 60 * 60 * 24 * 45 });

@ -19,6 +19,7 @@ export class Subscriptions extends Base {
this.tryEnsureIndex({ rid: 1, alert: 1, 'u._id': 1 });
this.tryEnsureIndex({ rid: 1, roles: 1 });
this.tryEnsureIndex({ 'u._id': 1, name: 1, t: 1 });
this.tryEnsureIndex({ name: 1, t: 1 });
this.tryEnsureIndex({ open: 1 });
this.tryEnsureIndex({ alert: 1 });
this.tryEnsureIndex({ ts: 1 });

@ -8,13 +8,15 @@ import { getMongoInfo } from '../../../utils/server/functions/getMongoInfo';
const baseName = 'rocketchat_';
const trash = new Mongo.Collection(`${ baseName }_trash`);
export const trash = new Mongo.Collection(`${ baseName }_trash`);
try {
trash._ensureIndex({ collection: 1 });
trash._ensureIndex({ __collection__: 1 });
trash._ensureIndex(
{ _deletedAt: 1 },
{ expireAfterSeconds: 60 * 60 * 24 * 30 },
);
trash._ensureIndex({ rid: 1, __collection__: 1, _deletedAt: 1 });
} catch (e) {
console.log(e);
}

@ -188,4 +188,5 @@ import './v188';
import './v189';
import './v190';
import './v191';
import './v192';
import './xrun';

@ -0,0 +1,28 @@
import { Migrations } from '../../../app/migrations/server';
import { Messages, Rooms } from '../../../app/models/server';
import { trash } from '../../../app/models/server/models/_BaseDb';
Migrations.add({
version: 192,
up() {
try {
trash._dropIndex({ collection: 1 });
} catch {
//
}
Messages.tryDropIndex({ rid: 1, ts: 1 });
Rooms.tryDropIndex({ 'tokenpass.tokens.token': 1 });
Rooms.tryEnsureIndex({ 'tokenpass.tokens.token': 1 }, { sparse: true });
Rooms.tryDropIndex({ default: 1 });
Rooms.tryEnsureIndex({ default: 1 }, { sparse: true });
Rooms.tryDropIndex({ featured: 1 });
Rooms.tryEnsureIndex({ featured: 1 }, { sparse: true });
Rooms.tryDropIndex({ muted: 1 });
Rooms.tryEnsureIndex({ muted: 1 }, { sparse: true });
},
});
Loading…
Cancel
Save