mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-04-09 22:46:12 +00:00
refactor(user): lazy-load relations
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
4483d2b898
commit
977ed4b9fa
4 changed files with 17 additions and 17 deletions
|
@ -166,7 +166,7 @@ describe('AuthService', () => {
|
|||
const accessTokenHash = await hashPassword(token);
|
||||
jest.spyOn(userRepo, 'findOne').mockResolvedValueOnce({
|
||||
...user,
|
||||
authTokens: [authToken],
|
||||
authTokens: Promise.resolve([authToken]),
|
||||
});
|
||||
jest.spyOn(authTokenRepo, 'findOne').mockResolvedValue({
|
||||
...authToken,
|
||||
|
@ -183,7 +183,7 @@ describe('AuthService', () => {
|
|||
);
|
||||
expect(userByToken).toEqual({
|
||||
...user,
|
||||
authTokens: [authToken],
|
||||
authTokens: Promise.resolve([authToken]),
|
||||
});
|
||||
});
|
||||
describe('fails:', () => {
|
||||
|
|
|
@ -65,9 +65,9 @@ export class AuthService {
|
|||
identifier: string,
|
||||
validUntil: TimestampMillis,
|
||||
): Promise<AuthTokenWithSecretDto> {
|
||||
user.authTokens = await this.getTokensByUser(user);
|
||||
user.authTokens = this.getTokensByUser(user);
|
||||
|
||||
if (user.authTokens.length >= 200) {
|
||||
if ((await user.authTokens).length >= 200) {
|
||||
// This is a very high ceiling unlikely to hinder legitimate usage,
|
||||
// but should prevent possible attack vectors
|
||||
throw new TooManyTokensError(
|
||||
|
|
|
@ -78,7 +78,7 @@ createConnection({
|
|||
notes[i].revisions = Promise.all([revision]);
|
||||
notes[i].userPermissions = Promise.resolve([]);
|
||||
notes[i].groupPermissions = Promise.resolve([]);
|
||||
user.ownedNotes = [notes[i]];
|
||||
user.ownedNotes = Promise.resolve([notes[i]]);
|
||||
await connection.manager.save([
|
||||
notes[i],
|
||||
user,
|
||||
|
|
|
@ -53,25 +53,25 @@ export class User {
|
|||
email: string | null;
|
||||
|
||||
@OneToMany((_) => Note, (note) => note.owner)
|
||||
ownedNotes: Note[];
|
||||
ownedNotes: Promise<Note[]>;
|
||||
|
||||
@OneToMany((_) => AuthToken, (authToken) => authToken.user)
|
||||
authTokens: AuthToken[];
|
||||
authTokens: Promise<AuthToken[]>;
|
||||
|
||||
@OneToMany((_) => Identity, (identity) => identity.user)
|
||||
identities: Promise<Identity[]>;
|
||||
|
||||
@ManyToMany((_) => Group, (group) => group.members)
|
||||
groups: Group[];
|
||||
groups: Promise<Group[]>;
|
||||
|
||||
@OneToMany((_) => HistoryEntry, (historyEntry) => historyEntry.user)
|
||||
historyEntries: HistoryEntry[];
|
||||
historyEntries: Promise<HistoryEntry[]>;
|
||||
|
||||
@OneToMany((_) => MediaUpload, (mediaUpload) => mediaUpload.user)
|
||||
mediaUploads: MediaUpload[];
|
||||
mediaUploads: Promise<MediaUpload[]>;
|
||||
|
||||
@OneToMany(() => Author, (author) => author.user)
|
||||
authors: Author[];
|
||||
authors: Promise<Author[]>;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
private constructor() {}
|
||||
|
@ -85,13 +85,13 @@ export class User {
|
|||
newUser.displayName = displayName;
|
||||
newUser.photo = null;
|
||||
newUser.email = null;
|
||||
newUser.ownedNotes = [];
|
||||
newUser.authTokens = [];
|
||||
newUser.ownedNotes = Promise.resolve([]);
|
||||
newUser.authTokens = Promise.resolve([]);
|
||||
newUser.identities = Promise.resolve([]);
|
||||
newUser.groups = [];
|
||||
newUser.historyEntries = [];
|
||||
newUser.mediaUploads = [];
|
||||
newUser.authors = [];
|
||||
newUser.groups = Promise.resolve([]);
|
||||
newUser.historyEntries = Promise.resolve([]);
|
||||
newUser.mediaUploads = Promise.resolve([]);
|
||||
newUser.authors = Promise.resolve([]);
|
||||
return newUser;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue