mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-18 17:25:16 -04:00
refactor: move typeorm store into new session module
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
14ee7485ad
commit
57365bb727
16 changed files with 204 additions and 49 deletions
35
src/session/session.service.ts
Normal file
35
src/session/session.service.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { TypeormStore } from 'connect-typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { DatabaseType } from '../config/database-type.enum';
|
||||
import databaseConfiguration, {
|
||||
DatabaseConfig,
|
||||
} from '../config/database.config';
|
||||
import { Session } from '../users/session.entity';
|
||||
|
||||
@Injectable()
|
||||
export class SessionService {
|
||||
private readonly typeormStore: TypeormStore;
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Session) private sessionRepository: Repository<Session>,
|
||||
@Inject(databaseConfiguration.KEY)
|
||||
private dbConfig: DatabaseConfig,
|
||||
) {
|
||||
this.typeormStore = new TypeormStore({
|
||||
cleanupLimit: 2,
|
||||
limitSubquery: dbConfig.type !== DatabaseType.MARIADB,
|
||||
}).connect(sessionRepository);
|
||||
}
|
||||
|
||||
getTypeormStore(): TypeormStore {
|
||||
return this.typeormStore;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue