-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redirects GraphQL API performance improvements (#2632)
Large number of redirects can cause issues in real projects. Help on improving the situation by making the API a bit faster.(that alone won't be the solution). - Add fixtures that create 7000 redirects (for this the additional exports are needed) - Add a relatively simple performance optimization in redirects resolver: Call `this.pageTreeReadApi.preloadNodes(scope);` to load the whole page tree into memory, as most redirects will access it (when they are internal) - Local tests showed (when loading 100 redirects) ~250ms (before) vs ~100ms (after) (!) - (Demo only) Add an index on `Redirect.scope_domain` - No difference in Demo performance, but much needed in "real" multidomain applications - Unfortunately this won't be generated by MikroORM, as the redirect entity is in library only - And increase the maximum limit for paginated redirects query from 100 to 1000 - Not much improvement, but still ~4.8s (before) vs ~3.2s (after) (both with preloadNodes) --------- Co-authored-by: Johannes Obermair <[email protected]>
- Loading branch information
1 parent
8f23414
commit cc2a117
Showing
11 changed files
with
110 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@comet/cms-api": patch | ||
--- | ||
|
||
Redirects: Improve GraphQL API performance by preloading the page tree to speed up target page lookup | ||
|
||
Also, increase the maximum limit from 100 to 1000. |
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
43 changes: 43 additions & 0 deletions
43
demo/api/src/db/fixtures/generators/redirects-fixture.service.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,43 @@ | ||
import { RedirectGenerationType, RedirectInterface, REDIRECTS_LINK_BLOCK, RedirectsLinkBlock, RedirectSourceTypeValues } from "@comet/cms-api"; | ||
import { InjectRepository } from "@mikro-orm/nestjs"; | ||
import { EntityRepository } from "@mikro-orm/postgresql"; | ||
import { Inject, Injectable } from "@nestjs/common"; | ||
|
||
@Injectable() | ||
export class RedirectsFixtureService { | ||
constructor( | ||
@Inject(REDIRECTS_LINK_BLOCK) private readonly redirectsLinkBlock: RedirectsLinkBlock, | ||
@InjectRepository("Redirect") private readonly repository: EntityRepository<RedirectInterface>, | ||
) {} | ||
|
||
async generateRedirects(): Promise<void> { | ||
console.log("Generating redirects..."); | ||
|
||
for (let i = 0; i < 7000; i++) { | ||
this.repository.create({ | ||
generationType: RedirectGenerationType.manual, | ||
source: `/redirect-${i}`, | ||
target: this.redirectsLinkBlock | ||
.blockInputFactory({ | ||
attachedBlocks: [ | ||
{ | ||
type: "internal", | ||
props: { | ||
targetPageId: "aaa585d3-eca1-47c9-8852-9370817b49ac", | ||
}, | ||
}, | ||
], | ||
activeType: "internal", | ||
}) | ||
.transformToBlockData(), | ||
active: true, | ||
scope: { | ||
domain: "main", | ||
language: "en", | ||
}, | ||
sourceType: RedirectSourceTypeValues.path, | ||
}); | ||
} | ||
await this.repository.getEntityManager().flush(); | ||
} | ||
} |
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,12 @@ | ||
import { Migration } from '@mikro-orm/migrations'; | ||
|
||
export class Migration20241015162102 extends Migration { | ||
|
||
async up(): Promise<void> { | ||
this.addSql('CREATE INDEX "Redirect_scope_domain" on "Redirect" ("scope_domain")'); | ||
} | ||
|
||
async down(): Promise<void> { | ||
this.addSql('DROP INDEX "Redirect_scope_domain"'); | ||
} | ||
} |
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