Browse Source

perf(core): Add indexes on date cols for orders & job items (#3614)

BREAKING CHANGE: Indexes have been added on the columns `orderPlacedAt` in the Order table, and `createdAt` in the JobItem table (for those using the DefaultJobQueuePlugin). This will require a non-destructive DB migration be performed to add these indexes to your schema.
oidt 6 months ago
parent
commit
ceb52790c6

+ 1 - 0
packages/core/src/entity/order/order.entity.ts

@@ -88,6 +88,7 @@ export class Order extends VendureEntity implements ChannelAware, HasCustomField
      * This is governed by the {@link OrderPlacedStrategy}.
      */
     @Column({ nullable: true })
+    @Index()
     orderPlacedAt?: Date;
 
     @Index()

+ 3 - 1
packages/core/src/plugin/default-job-queue-plugin/job-record.entity.ts

@@ -1,9 +1,11 @@
 import { JobState } from '@vendure/common/lib/generated-types';
 import { DeepPartial } from '@vendure/common/lib/shared-types';
-import { Column, Entity } from 'typeorm';
+import { Column, Entity, Index } from 'typeorm';
 
 import { VendureEntity } from '../../entity/base/base.entity';
 
+// createdAt is coming from base entity VendureEntity and is not explicitly defined here
+@Index(['createdAt'])
 @Entity()
 export class JobRecord extends VendureEntity {
     constructor(input: DeepPartial<JobRecord>) {

+ 1 - 0
packages/dashboard/src/app/routes/_authenticated/_system/job-queue.tsx

@@ -52,6 +52,7 @@ function JobQueuePage() {
         <ListPage
             pageId="job-queue-list"
             title="Job Queue"
+            defaultSort={[{ id: 'createdAt', desc: true }]}
             listQuery={jobListDocument}
             route={Route}
             customizeColumns={{