mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-28 20:10:58 -05:00
refactor(author): lazy-load relations
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
de6d75238c
commit
5d7b544e1f
4 changed files with 10 additions and 10 deletions
|
@ -39,21 +39,21 @@ export class Author {
|
||||||
* Only contains sessions for anonymous users, which don't have a user set
|
* Only contains sessions for anonymous users, which don't have a user set
|
||||||
*/
|
*/
|
||||||
@OneToMany(() => Session, (session) => session.author)
|
@OneToMany(() => Session, (session) => session.author)
|
||||||
sessions: Session[];
|
sessions: Promise<Session[]>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User that this author corresponds to
|
* User that this author corresponds to
|
||||||
* Only set when the user was identified (by a browser session) as a registered user at edit-time
|
* Only set when the user was identified (by a browser session) as a registered user at edit-time
|
||||||
*/
|
*/
|
||||||
@ManyToOne(() => User, (user) => user.authors, { nullable: true })
|
@ManyToOne(() => User, (user) => user.authors, { nullable: true })
|
||||||
user: User | null;
|
user: Promise<User | null>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of edits that this author created
|
* List of edits that this author created
|
||||||
* All edits must belong to the same note
|
* All edits must belong to the same note
|
||||||
*/
|
*/
|
||||||
@OneToMany(() => Edit, (edit) => edit.author)
|
@OneToMany(() => Edit, (edit) => edit.author)
|
||||||
edits: Edit[];
|
edits: Promise<Edit[]>;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
private constructor() {}
|
private constructor() {}
|
||||||
|
@ -61,9 +61,9 @@ export class Author {
|
||||||
public static create(color: number): Omit<Author, 'id'> {
|
public static create(color: number): Omit<Author, 'id'> {
|
||||||
const newAuthor = new Author();
|
const newAuthor = new Author();
|
||||||
newAuthor.color = color;
|
newAuthor.color = color;
|
||||||
newAuthor.sessions = [];
|
newAuthor.sessions = Promise.resolve([]);
|
||||||
newAuthor.user = null;
|
newAuthor.user = Promise.resolve(null);
|
||||||
newAuthor.edits = [];
|
newAuthor.edits = Promise.resolve([]);
|
||||||
return newAuthor;
|
return newAuthor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -703,7 +703,7 @@ describe('NotesService', () => {
|
||||||
it('works', async () => {
|
it('works', async () => {
|
||||||
const user = User.create('hardcoded', 'Testy') as User;
|
const user = User.create('hardcoded', 'Testy') as User;
|
||||||
const author = Author.create(1);
|
const author = Author.create(1);
|
||||||
author.user = user;
|
author.user = Promise.resolve(user);
|
||||||
const group = Group.create('testGroup', 'testGroup', false) as Group;
|
const group = Group.create('testGroup', 'testGroup', false) as Group;
|
||||||
const content = 'testContent';
|
const content = 'testContent';
|
||||||
jest
|
jest
|
||||||
|
@ -798,7 +798,7 @@ describe('NotesService', () => {
|
||||||
it('works', async () => {
|
it('works', async () => {
|
||||||
const user = User.create('hardcoded', 'Testy') as User;
|
const user = User.create('hardcoded', 'Testy') as User;
|
||||||
const author = Author.create(1);
|
const author = Author.create(1);
|
||||||
author.user = user;
|
author.user = Promise.resolve(user);
|
||||||
const otherUser = User.create('other hardcoded', 'Testy2') as User;
|
const otherUser = User.create('other hardcoded', 'Testy2') as User;
|
||||||
otherUser.username = 'other hardcoded user';
|
otherUser.username = 'other hardcoded user';
|
||||||
const group = Group.create('testGroup', 'testGroup', false) as Group;
|
const group = Group.create('testGroup', 'testGroup', false) as Group;
|
||||||
|
|
|
@ -343,7 +343,7 @@ export class NotesService {
|
||||||
if (lastRevision && lastRevision.edits) {
|
if (lastRevision && lastRevision.edits) {
|
||||||
// Sort the last Revisions Edits by their updatedAt Date to get the latest one
|
// Sort the last Revisions Edits by their updatedAt Date to get the latest one
|
||||||
// the user of that Edit is the updateUser
|
// the user of that Edit is the updateUser
|
||||||
return lastRevision.edits.sort(
|
return await lastRevision.edits.sort(
|
||||||
(a, b) => b.updatedAt.getTime() - a.updatedAt.getTime(),
|
(a, b) => b.updatedAt.getTime() - a.updatedAt.getTime(),
|
||||||
)[0].author.user;
|
)[0].author.user;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ createConnection({
|
||||||
const identity = Identity.create(user, ProviderType.LOCAL, false);
|
const identity = Identity.create(user, ProviderType.LOCAL, false);
|
||||||
identity.passwordHash = await hashPassword(password);
|
identity.passwordHash = await hashPassword(password);
|
||||||
connection.manager.create(Identity, identity);
|
connection.manager.create(Identity, identity);
|
||||||
author.user = user;
|
author.user = Promise.resolve(user);
|
||||||
const revision = Revision.create(
|
const revision = Revision.create(
|
||||||
'This is a test note',
|
'This is a test note',
|
||||||
'This is a test note',
|
'This is a test note',
|
||||||
|
|
Loading…
Reference in a new issue