Skip to content

Commit

Permalink
Harmonize usage of uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdax98 committed Jan 2, 2025
1 parent c1e80a0 commit b42bd2a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/api/cms-api/src/dependencies/dependencies.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Injectable, Logger, Type } from "@nestjs/common";
import { INJECTABLE_WATERMARK } from "@nestjs/common/constants";
import { ModuleRef } from "@nestjs/core";
import { subMinutes } from "date-fns";
import { v4 } from "uuid";
import { v4 as uuid } from "uuid";

import { EntityInfoGetter, EntityInfoServiceInterface } from "./decorators/entity-info.decorator";
import { DiscoverService } from "./discover.service";
Expand Down Expand Up @@ -95,18 +95,18 @@ export class DependenciesService {

async refreshViews(options?: { force?: boolean; awaitRefresh?: boolean }): Promise<void> {
const refresh = async (options?: { concurrently: boolean }) => {
const uuid = v4();
const id = uuid();
// Before forking the entity manager, race conditions occurred frequently
// when executing the refresh asynchronous
const forkedEntityManager = this.entityManager.fork();
console.time(`refresh materialized block dependency ${uuid}`);
console.time(`refresh materialized block dependency ${id}`);
const blockIndexRefresh = this.refreshRepository.create({ startedAt: new Date() });
await forkedEntityManager.persistAndFlush(blockIndexRefresh);

await forkedEntityManager.execute(`REFRESH MATERIALIZED VIEW ${options?.concurrently ? "CONCURRENTLY" : ""} block_index_dependencies`);

await forkedEntityManager.persistAndFlush(Object.assign(blockIndexRefresh, { finishedAt: subMinutes(new Date(), 5) }));
console.timeEnd(`refresh materialized block dependency ${uuid}`);
console.timeEnd(`refresh materialized block dependency ${id}`);
};

const abortActiveRefreshes = async (activeRefreshes: PGStatActivity[]) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseEntity, Entity, PrimaryKey, Property } from "@mikro-orm/core";
import { Field, ID, ObjectType, registerEnumType } from "@nestjs/graphql";
import { GraphQLJSONObject } from "graphql-scalars";
import { v4 } from "uuid";
import { v4 as uuid } from "uuid";

import { ContentScope } from "../interfaces/content-scope.interface";

Expand All @@ -18,7 +18,7 @@ registerEnumType(UserPermissionSource, {
export class UserPermission extends BaseEntity<UserPermission, "id"> {
@Field(() => ID)
@PrimaryKey({ type: "uuid" })
id: string = v4();
id: string = uuid();

@Property()
userId: string;
Expand Down

0 comments on commit b42bd2a

Please sign in to comment.