Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fifty-moles-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/model-typings": patch
"@rocket.chat/models": patch
---

Fixes an issue where the app's logs index was not being created by default sometimes, also set to be always 30 days
29 changes: 1 addition & 28 deletions apps/meteor/ee/server/apps/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const startupApp = async function startupApp() {
},
],
public: true,
hidden: false,
hidden: true,
alert: 'Apps_Logs_TTL_Alert',
});

Expand Down Expand Up @@ -69,33 +69,6 @@ export const startupApp = async function startupApp() {
// Disable apps that depend on add-ons (external modules) if they are invalidated
License.onModule(disableAppsWithAddonsCallback);

settings.watch('Apps_Logs_TTL', async (value) => {
// TODO: remove this feature, initialized is always false first time
if (!Apps.isInitialized()) {
return;
}
let expireAfterSeconds = 0;

switch (value) {
case '7_days':
expireAfterSeconds = 604800;
break;
case '14_days':
expireAfterSeconds = 1209600;
break;
case '30_days':
expireAfterSeconds = 2592000;
break;
}

if (!expireAfterSeconds) {
return;
}

const model = Apps._logModel;
await model?.resetTTLIndex(expireAfterSeconds);
});

Apps.initialize();

void Apps.load();
Expand Down
1 change: 0 additions & 1 deletion packages/model-typings/src/models/IAppLogsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ import type { IBaseModel } from './IBaseModel';

// TODO: type for AppLogs
export interface IAppLogsModel extends IBaseModel<any> {
resetTTLIndex(expireAfterSeconds: number): Promise<void>;
remove(query: Filter<any>): Promise<DeleteResult>;
}
25 changes: 16 additions & 9 deletions packages/models/src/models/AppLogsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@ import type { Db, DeleteResult, Filter } from 'mongodb';
import { BaseRaw } from './BaseRaw';

export class AppsLogsModel extends BaseRaw<any> implements IAppLogsModel {
constructor(db: Db) {
super(db, 'apps_logs', undefined, { _updatedAtIndexOptions: { expireAfterSeconds: 60 * 60 * 24 * 30 } });
constructor(
db: Db,
private readonly expireAfterSeconds: number = 60 * 60 * 24 * 30,
) {
super(db, 'apps_logs', undefined);
}

remove(query: Filter<any>): Promise<DeleteResult> {
return this.col.deleteMany(query);
protected modelIndexes() {
return [
{
key: {
_updatedAt: 1,
},
expireAfterSeconds: this.expireAfterSeconds,
},
];
}

async resetTTLIndex(expireAfterSeconds: number): Promise<void> {
if (await this.col.indexExists('_updatedAt_1')) {
await this.col.dropIndex('_updatedAt_1');
}
await this.col.createIndex({ _updatedAt: 1 }, { expireAfterSeconds });
remove(query: Filter<any>): Promise<DeleteResult> {
return this.col.deleteMany(query);
}
}
6 changes: 1 addition & 5 deletions packages/models/src/models/BaseRaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type ModelOptions = {
preventSetUpdatedAt?: boolean;
collectionNameResolver?: (name: string) => string;
collection?: CollectionOptions;
_updatedAtIndexOptions?: Omit<IndexDescription, 'key'>;
};

export abstract class BaseRaw<
Expand Down Expand Up @@ -74,7 +73,7 @@ export abstract class BaseRaw<
private db: Db,
protected name: string,
protected trash?: Collection<TDeleted>,
private options?: ModelOptions,
options?: ModelOptions,
) {
this.collectionName = options?.collectionNameResolver ? options.collectionNameResolver(name) : getCollectionName(name);

Expand All @@ -91,9 +90,6 @@ export abstract class BaseRaw<

public async createIndexes() {
const indexes = this.modelIndexes();
if (this.options?._updatedAtIndexOptions) {
indexes?.push({ ...this.options._updatedAtIndexOptions, key: { _updatedAt: 1 } });
}

if (indexes?.length) {
if (this.pendingIndexes) {
Expand Down
Loading