Improve perfs to get log details
MODIFY
src/server/rest/v1/service/LoggingService.ts
src/server/rest/v1/service/LoggingService.ts
@@ -34,11 +34,6 @@ export default class LoggingService {
public static async handleGetLog(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
const filteredRequest = LoggingSecurity.filterLogRequest(req.query);
- // Get logs
- const logging = await LoggingStorage.getLog(req.user.tenantID, filteredRequest.ID, [
- 'id', 'level', 'timestamp', 'type', 'source', 'host', 'process', 'action', 'message',
- 'user.name', 'user.firstName', 'actionOnUser.name', 'actionOnUser.firstName', 'hasDetailedMessages', 'detailedMessages'
- ]);
// Check auth
if (!await Authorizations.canReadLog(req.user)) {
throw new AppAuthError({
@@ -48,7 +43,11 @@ export default class LoggingService {
module: MODULE_NAME, method: 'handleGetLog'
});
}
- // Return
+ // Get Log
+ const logging = await LoggingStorage.getLog(req.user.tenantID, filteredRequest.ID, [
+ 'id', 'level', 'timestamp', 'type', 'source', 'host', 'process', 'action', 'message',
+ 'user.name', 'user.firstName', 'actionOnUser.name', 'actionOnUser.firstName', 'hasDetailedMessages', 'detailedMessages'
+ ]);
res.json(logging);
next();
}

MODIFY
src/storage/mongodb/LoggingStorage.ts
src/storage/mongodb/LoggingStorage.ts
@@ -163,12 +163,7 @@ export default class LoggingStorage {
aggregation.push({ $limit: Constants.DB_RECORD_COUNT_CEIL });
}
const loggingsCountMDB = await global.database.getCollection<any>(tenantID, 'logs')
- .aggregate([...aggregation, { $count: 'count' }], {
- collation: {
- locale: Constants.DEFAULT_LOCALE,
- strength: 2
- }
- })
+ .aggregate([...aggregation, { $count: 'count' }])
.toArray();
// Check if only the total count is requested
if (dbParams.onlyRecordCount) {

Improve perfs to get log details