-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve previous sessions list performance (#298)
- Loading branch information
1 parent
3449e19
commit a34e611
Showing
20 changed files
with
314 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { ViewEntity, ViewColumn } from 'typeorm'; | ||
import { User, SessionMetadata } from '@retrospected/common'; | ||
|
||
@ViewEntity({ | ||
expression: ` | ||
select | ||
s.id, | ||
s.name, | ||
s.created, | ||
( | ||
select to_jsonb(cb) from ( | ||
select cbu.id, cbu.name, cbu.photo from users cbu | ||
where cbu.id = s."createdById" | ||
) as cb | ||
) as "createdBy", | ||
s.encrypted, | ||
s.locked, | ||
(select count(*) from posts p where p."sessionId" = s.id and p.action is not null) as "numberOfActions", | ||
(select count(*) from posts p where p."sessionId" = s.id) as "numberOfPosts", | ||
( | ||
select count(*) from votes vv | ||
left join posts vp on vp.id = vv."postId" | ||
where vp."sessionId" = s.id | ||
) as "numberOfVotes", | ||
( | ||
select json_agg(vis) from ( | ||
select vu.id, vu.name, vu.photo from visitors v | ||
join users vu on vu.id = v."usersId" | ||
where v."sessionsId" = s.id | ||
) as vis | ||
) as participants | ||
from sessions s | ||
left join users u on s."createdById" = u.id | ||
order by s.updated desc | ||
`, | ||
}) | ||
export default class SessionView { | ||
@ViewColumn() | ||
public id: string; | ||
@ViewColumn() | ||
public name: string; | ||
@ViewColumn() | ||
public created: Date; | ||
@ViewColumn() | ||
public createdBy: User; | ||
@ViewColumn() | ||
public encrypted: string | null; | ||
@ViewColumn() | ||
public locked: boolean; | ||
@ViewColumn() | ||
public numberOfActions: number; | ||
@ViewColumn() | ||
public numberOfPosts: number; | ||
@ViewColumn() | ||
public numberOfVotes: number; | ||
@ViewColumn() | ||
public participants: User[]; | ||
|
||
constructor(id: string, name: string) { | ||
this.id = id; | ||
this.name = name; | ||
this.created = new Date(); | ||
this.createdBy = { id: '0', name: '', photo: '' }; | ||
this.encrypted = null; | ||
this.locked = false; | ||
this.numberOfActions = 0; | ||
this.numberOfPosts = 0; | ||
this.numberOfVotes = 0; | ||
this.participants = []; | ||
} | ||
|
||
toJson(userId: string): SessionMetadata { | ||
return { | ||
...this, | ||
canBeDeleted: userId === this.createdBy.id, | ||
lockedForUser: | ||
this.locked && this.participants | ||
? !this.participants.map((v) => v.id).includes(userId) | ||
: false, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
export class IndexPost1632066879336 implements MigrationInterface { | ||
name = 'IndexPost1632066879336' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`CREATE INDEX "IDX_764b665f832e28c01595ec15cf" ON "public"."posts" ("sessionId") `); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP INDEX "public"."IDX_764b665f832e28c01595ec15cf"`); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
backend/src/db/migrations/1632067126663-IndexEverything.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
export class IndexEverything1632067126663 implements MigrationInterface { | ||
name = 'IndexEverything1632067126663' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`CREATE INDEX "IDX_9ad140fba0b4ad9559e6530282" ON "public"."groups" ("sessionId") `); | ||
await queryRunner.query(`CREATE INDEX "IDX_898cf6af34722df13f760cc364" ON "public"."groups" ("userId") `); | ||
await queryRunner.query(`CREATE INDEX "IDX_5169384e31d0989699a318f3ca" ON "public"."votes" ("userId") `); | ||
await queryRunner.query(`CREATE INDEX "IDX_b5b05adc89dda0614276a13a59" ON "public"."votes" ("postId") `); | ||
await queryRunner.query(`CREATE INDEX "IDX_c58b12b1a7b4012bb238bc2654" ON "public"."templates" ("createdById") `); | ||
await queryRunner.query(`CREATE INDEX "IDX_331400b3a08ee505d42ddba1db" ON "public"."subscriptions" ("ownerId") `); | ||
await queryRunner.query(`CREATE INDEX "IDX_a10dca6aa6bda5865287bf2792" ON "public"."users_identities" ("userId") `); | ||
await queryRunner.query(`CREATE INDEX "IDX_5b086b03bb64304390cec7635e" ON "public"."users" ("defaultTemplateId") `); | ||
await queryRunner.query(`CREATE INDEX "IDX_d10acbe503da4c56853181efc9" ON "public"."posts" ("groupId") `); | ||
await queryRunner.query(`CREATE INDEX "IDX_ae05faaa55c866130abef6e1fe" ON "public"."posts" ("userId") `); | ||
await queryRunner.query(`CREATE INDEX "IDX_d26fe2e6102cd9c47650a0d7a6" ON "public"."sessions" ("createdById") `); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP INDEX "public"."IDX_d26fe2e6102cd9c47650a0d7a6"`); | ||
await queryRunner.query(`DROP INDEX "public"."IDX_ae05faaa55c866130abef6e1fe"`); | ||
await queryRunner.query(`DROP INDEX "public"."IDX_d10acbe503da4c56853181efc9"`); | ||
await queryRunner.query(`DROP INDEX "public"."IDX_5b086b03bb64304390cec7635e"`); | ||
await queryRunner.query(`DROP INDEX "public"."IDX_a10dca6aa6bda5865287bf2792"`); | ||
await queryRunner.query(`DROP INDEX "public"."IDX_331400b3a08ee505d42ddba1db"`); | ||
await queryRunner.query(`DROP INDEX "public"."IDX_c58b12b1a7b4012bb238bc2654"`); | ||
await queryRunner.query(`DROP INDEX "public"."IDX_b5b05adc89dda0614276a13a59"`); | ||
await queryRunner.query(`DROP INDEX "public"."IDX_5169384e31d0989699a318f3ca"`); | ||
await queryRunner.query(`DROP INDEX "public"."IDX_898cf6af34722df13f760cc364"`); | ||
await queryRunner.query(`DROP INDEX "public"."IDX_9ad140fba0b4ad9559e6530282"`); | ||
} | ||
|
||
} |
Oops, something went wrong.