refactor: Convert trash to raw (#28939)

pull/28967/head
Kevin Aleman 3 years ago committed by GitHub
parent ae520dd29a
commit e480563602
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      apps/meteor/server/database/trash.ts
  2. 22
      apps/meteor/server/models/raw/Trash.ts

@ -1,17 +1,5 @@
import { Mongo } from 'meteor/mongo';
import type { Collection } from 'mongodb';
import { TrashRaw } from '../models/raw/Trash';
import { db } from './utils';
import { SystemLogger } from '../lib/logger/system';
// TODO need to improve how other files imports this
export const trash = new Mongo.Collection('rocketchat__trash');
try {
trash._ensureIndex({ __collection__: 1 });
trash._ensureIndex({ _deletedAt: 1 }, { expireAfterSeconds: 60 * 60 * 24 * 30 });
trash._ensureIndex({ rid: 1, __collection__: 1, _deletedAt: 1 });
} catch (e) {
SystemLogger.error(e);
}
export const trashCollection = trash.rawCollection() as Collection<any>;
const Trash = new TrashRaw(db);
export const trashCollection = Trash.col;

@ -0,0 +1,22 @@
import type { Db, IndexDescription } from 'mongodb';
import type { RocketChatRecordDeleted } from '@rocket.chat/core-typings';
import { BaseRaw } from './BaseRaw';
export class TrashRaw extends BaseRaw<RocketChatRecordDeleted<any>> {
constructor(db: Db) {
super(db, 'rocketchat__trash', undefined, {
collectionNameResolver(name) {
return name;
},
});
}
protected modelIndexes(): IndexDescription[] | undefined {
return [
{ key: { __collection__: 1 } },
{ key: { _deletedAt: 1 }, expireAfterSeconds: 60 * 60 * 24 * 30 },
{ key: { rid: 1, __collection__: 1, _deletedAt: 1 } },
];
}
}
Loading…
Cancel
Save