refactor(note): lazy-load relations

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-11-30 16:46:07 +01:00
parent d761ff7f4f
commit 235e4f647c
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
23 changed files with 343 additions and 284 deletions

View file

@ -36,21 +36,21 @@ export class Note {
(alias) => alias.note,
{ cascade: true }, // This ensures that embedded Aliases are automatically saved to the database
)
aliases: Alias[];
aliases: Promise<Alias[]>;
@OneToMany(
(_) => NoteGroupPermission,
(groupPermission) => groupPermission.note,
{ cascade: true }, // This ensures that embedded NoteGroupPermissions are automatically saved to the database
)
groupPermissions: NoteGroupPermission[];
groupPermissions: Promise<NoteGroupPermission[]>;
@OneToMany(
(_) => NoteUserPermission,
(userPermission) => userPermission.note,
{ cascade: true }, // This ensures that embedded NoteUserPermission are automatically saved to the database
)
userPermissions: NoteUserPermission[];
userPermissions: Promise<NoteUserPermission[]>;
@Column({
nullable: false,
@ -62,16 +62,16 @@ export class Note {
onDelete: 'CASCADE', // This deletes the Note, when the associated User is deleted
nullable: true,
})
owner: User | null;
owner: Promise<User | null>;
@OneToMany((_) => Revision, (revision) => revision.note, { cascade: true })
revisions: Promise<Revision[]>;
@OneToMany((_) => HistoryEntry, (historyEntry) => historyEntry.user)
historyEntries: HistoryEntry[];
historyEntries: Promise<HistoryEntry[]>;
@OneToMany((_) => MediaUpload, (mediaUpload) => mediaUpload.note)
mediaUploads: MediaUpload[];
mediaUploads: Promise<MediaUpload[]>;
@Column({
nullable: true,
@ -87,7 +87,7 @@ export class Note {
@ManyToMany((_) => Tag, (tag) => tag.notes, { eager: true, cascade: true })
@JoinTable()
tags: Tag[];
tags: Promise<Tag[]>;
// eslint-disable-next-line @typescript-eslint/no-empty-function
private constructor() {}
@ -101,18 +101,18 @@ export class Note {
const newNote = new Note();
newNote.publicId = generatePublicId();
newNote.aliases = alias
? [Alias.create(alias, newNote, true) as Alias]
: [];
newNote.userPermissions = [];
newNote.groupPermissions = [];
? Promise.resolve([Alias.create(alias, newNote, true) as Alias])
: Promise.resolve([]);
newNote.userPermissions = Promise.resolve([]);
newNote.groupPermissions = Promise.resolve([]);
newNote.viewCount = 0;
newNote.owner = owner;
newNote.owner = Promise.resolve(owner);
newNote.revisions = Promise.resolve([]);
newNote.historyEntries = [];
newNote.mediaUploads = [];
newNote.historyEntries = Promise.resolve([]);
newNote.mediaUploads = Promise.resolve([]);
newNote.description = null;
newNote.title = null;
newNote.tags = [];
newNote.tags = Promise.resolve([]);
return newNote;
}
}