mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-21 02:35:23 -04:00
refactor(note): lazy-load relations
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
d761ff7f4f
commit
235e4f647c
23 changed files with 343 additions and 284 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue