message: refactor(stitcher): parallelize DB queries
diff: @@ -80,13 +80,8 @@ export class Stitcher {
  // one row (except in abnormal cases where the stitch was invoked for
  // something that didn't exist at all, in which case it's zero rows).
  // The join with the temporary incoming_references still gives one row.
  - const processedResult: Array<{
  - entityId: string;
  - processedEntity?: string;
  - errors: string;
  - incomingReferenceCount: string | number;
  - previousHash?: string;
  - }> = await this.database
  + const [processedResult, relationsResult] = await Promise.all([
  + this.database
  .with('incoming_references', function incomingReferences(builder) {
  return builder
  .from('refresh_state_references')
  @@ -105,12 +100,8 @@ export class Stitcher {
  .crossJoin(this.database.raw('incoming_references'))
  .leftOuterJoin('final_entities', {
  'final_entities.entity_id': 'refresh_state.entity_id',
  - });
  -
  - const relationsResult: Array<{
  - relationType: string;
  - relationTarget: string;
  - }> = await this.database
  + }),
  + this.database
  .distinct({
  relationType: 'type',
  relationTarget: 'target_entity_ref',
  @@ -118,7 +109,8 @@ export class Stitcher {
  .from('relations')
  .where({ source_entity_ref: entityRef })
  .orderBy('relationType', 'asc')
  - .orderBy('relationTarget', 'asc');
  + .orderBy('relationTarget', 'asc'),
  + ]);
  // If there were no rows returned, it would mean that there was no
  // matching row even in the refresh_state. This can happen for example
  