Убран лишний код. Скорректированы docker и package файлы. Переработано взаимодействие с бд - упрощена логика.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { distinctUntilChanged, from, map, Observable, switchMap, timer } from 'rxjs';
|
||||
import { getIntegerConfig } from '../common/config-number';
|
||||
import { CurrentResponseDto } from './dto/current-response.dto';
|
||||
import { GetCurrentDto } from './dto/get-current.dto';
|
||||
import { CurrentService } from './current.service';
|
||||
@@ -15,21 +13,13 @@ type CurrentSnapshot = {
|
||||
response: CurrentResponseDto;
|
||||
};
|
||||
|
||||
const DEFAULT_CURRENT_EVENTS_POLL_MS = 1_000;
|
||||
|
||||
@Injectable()
|
||||
export class CurrentEventsService {
|
||||
constructor(
|
||||
private readonly current: CurrentService,
|
||||
private readonly config: ConfigService,
|
||||
) {}
|
||||
constructor(private readonly current: CurrentService) {}
|
||||
|
||||
/** Отправляет SSE-события current только при изменении снимка данных по edge/tags. */
|
||||
stream(query: GetCurrentDto): Observable<CurrentSseMessage> {
|
||||
const pollMs = Math.max(
|
||||
getIntegerConfig(this.config, 'CURRENT_EVENTS_POLL_MS', DEFAULT_CURRENT_EVENTS_POLL_MS),
|
||||
250,
|
||||
);
|
||||
const pollMs = Number(process.env.CURRENT_EVENTS_POLL_MS);
|
||||
|
||||
return timer(0, pollMs).pipe(
|
||||
switchMap(() => from(this.createSnapshot(query))),
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { normalizeRequiredText } from '../common/normalize-text';
|
||||
import { CurrentResponseDto } from './dto/current-response.dto';
|
||||
import { GetCurrentDto } from './dto/get-current.dto';
|
||||
import { createCurrentResponse } from './current.mapper';
|
||||
@@ -11,7 +10,7 @@ export class CurrentService {
|
||||
|
||||
/** Нормализует фильтры и возвращает текущие значения по одному edge. */
|
||||
async findByEdge(query: GetCurrentDto): Promise<CurrentResponseDto> {
|
||||
const edge = normalizeRequiredText(query.edge, 'edge');
|
||||
const edge = query.edge;
|
||||
const tags = query.tags?.length ? query.tags : null;
|
||||
const rows = await this.repository.findByEdge(edge, tags);
|
||||
return createCurrentResponse(edge, rows);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { Transform } from 'class-transformer';
|
||||
import { IsArray, IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
||||
import { parseCommaSeparatedList } from '../../common/query-list';
|
||||
|
||||
export class GetCurrentDto {
|
||||
@IsNotEmpty()
|
||||
@@ -8,7 +6,6 @@ export class GetCurrentDto {
|
||||
edge!: string;
|
||||
|
||||
@IsOptional()
|
||||
@Transform(({ value }) => parseCommaSeparatedList(value))
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
tags?: string[];
|
||||
|
||||
Reference in New Issue
Block a user