Убран лишний код. Скорректированы docker и package файлы. Переработано взаимодействие с бд - упрощена логика.
This commit is contained in:
@@ -4,9 +4,6 @@ export type EdgeItemDto = {
|
||||
parentId: string | null;
|
||||
tagIds: string[];
|
||||
tagCount: number;
|
||||
currentTagCount: number;
|
||||
liveTagCount: number;
|
||||
lastDataAt: Date | null;
|
||||
};
|
||||
|
||||
export type EdgeResponseDto = {
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
import { Transform } from 'class-transformer';
|
||||
import { IsOptional, IsString } from 'class-validator';
|
||||
import { normalizeOptionalText } from '../../common/normalize-text';
|
||||
|
||||
export class GetEdgesDto {
|
||||
@IsOptional()
|
||||
@Transform(({ value }) => normalizeOptionalText(value))
|
||||
@IsString()
|
||||
parentId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@Transform(({ value }) => normalizeOptionalText(value))
|
||||
@IsString()
|
||||
search?: string;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,6 @@ export function createEdgeResponse(rows: EdgeRow[]): EdgeResponseDto {
|
||||
parentId: row.parent_id,
|
||||
tagIds: row.tag_ids ?? [],
|
||||
tagCount: row.tag_count,
|
||||
currentTagCount: row.current_tag_count,
|
||||
liveTagCount: row.live_tag_count,
|
||||
lastDataAt: row.last_data_at,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { EdgeRow } from './edge.types';
|
||||
export class EdgeRepository {
|
||||
constructor(private readonly db: DbService) {}
|
||||
|
||||
/** Читает каталог edge с легкими счетчиками свежести из текущих значений. */
|
||||
/** Читает каталог edge без расчетов по текущим значениям. */
|
||||
async findAll(parentId: string | null, search: string | null): Promise<EdgeRow[]> {
|
||||
const result = await this.db.query<EdgeRow>(
|
||||
`
|
||||
@@ -15,23 +15,14 @@ export class EdgeRepository {
|
||||
e.name,
|
||||
e.parent_id,
|
||||
e.tag_ids,
|
||||
cardinality(e.tag_ids)::integer AS tag_count,
|
||||
count(DISTINCT c.tag)::integer AS current_tag_count,
|
||||
count(DISTINCT c.tag) FILTER (
|
||||
WHERE c."updatedAt" >= now() - INTERVAL '30 seconds'
|
||||
)::integer AS live_tag_count,
|
||||
max(c."updatedAt") AS last_data_at
|
||||
cardinality(e.tag_ids)::integer AS tag_count
|
||||
FROM edge AS e
|
||||
LEFT JOIN current AS c
|
||||
ON c.edge = e.id
|
||||
AND (cardinality(e.tag_ids) = 0 OR c.tag = ANY(e.tag_ids))
|
||||
WHERE ($1::varchar IS NULL OR e.parent_id = $1::varchar)
|
||||
AND (
|
||||
$2::text IS NULL
|
||||
OR e.id ILIKE $2::text
|
||||
OR e.name ILIKE $2::text
|
||||
)
|
||||
GROUP BY e.id, e.name, e.parent_id, e.tag_ids
|
||||
ORDER BY e.name ASC, e.id ASC
|
||||
`,
|
||||
[parentId, search],
|
||||
|
||||
@@ -4,7 +4,4 @@ export type EdgeRow = {
|
||||
parent_id: string | null;
|
||||
tag_ids: string[];
|
||||
tag_count: number;
|
||||
current_tag_count: number;
|
||||
live_tag_count: number;
|
||||
last_data_at: Date | null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user