diff --git a/backend/src/metrics/metrics.service.ts b/backend/src/metrics/metrics.service.ts index 63f97817..2fe1ba69 100644 --- a/backend/src/metrics/metrics.service.ts +++ b/backend/src/metrics/metrics.service.ts @@ -1,4 +1,4 @@ -import { CACHE_TTL, CAUR_METRICS_URL, parseOutput, SpecificPackageMetrics } from "@./shared-lib" +import { CACHE_ROUTER_TTL, CAUR_METRICS_URL, parseOutput, SpecificPackageMetrics } from "@./shared-lib" import { Cache, CACHE_MANAGER } from "@nestjs/cache-manager" import { Inject, Injectable } from "@nestjs/common" import { Axios } from "axios" @@ -31,7 +31,7 @@ export class MetricsService { console.error(err) return [] }) - await this.cacheManager.set(cacheKey, data, CACHE_TTL) + await this.cacheManager.set(cacheKey, data, CACHE_ROUTER_TTL) } return data } @@ -53,7 +53,7 @@ export class MetricsService { console.error(err) return [] }) - await this.cacheManager.set(cacheKey, data, CACHE_TTL) + await this.cacheManager.set(cacheKey, data, CACHE_ROUTER_TTL) } return data } @@ -82,7 +82,7 @@ export class MetricsService { console.error(err) return metrics }) - await this.cacheManager.set(cacheKey, data, CACHE_TTL) + await this.cacheManager.set(cacheKey, data, CACHE_ROUTER_TTL) } return data } @@ -105,7 +105,7 @@ export class MetricsService { console.error(err) return [] }) - await this.cacheManager.set(cacheKey, data, CACHE_TTL) + await this.cacheManager.set(cacheKey, data, CACHE_ROUTER_TTL) } return data } @@ -129,7 +129,7 @@ export class MetricsService { console.error(err) return [] }) - await this.cacheManager.set(cacheKey, data, CACHE_TTL) + await this.cacheManager.set(cacheKey, data, CACHE_ROUTER_TTL) } return data } diff --git a/backend/src/telegram/telegram.service.ts b/backend/src/telegram/telegram.service.ts index a0f35cc8..3c2d36f6 100644 --- a/backend/src/telegram/telegram.service.ts +++ b/backend/src/telegram/telegram.service.ts @@ -1,4 +1,4 @@ -import { CACHE_TTL, CAUR_DEPLOY_LOG_ID, CAUR_NEWS_ID, TgMessage, TgMessageList } from "@./shared-lib" +import { CACHE_TELEGRAM_TTL, CAUR_DEPLOY_LOG_ID, CAUR_NEWS_ID, TgMessage, TgMessageList } from "@./shared-lib" import { CACHE_MANAGER, Cache } from "@nestjs/cache-manager" import { Inject, Injectable, Logger } from "@nestjs/common" import { getTdjson } from "prebuilt-tdlib" @@ -39,7 +39,7 @@ export class TelegramService { let data: TgMessage[] | undefined = await this.cacheManager.get(cacheKey) if (!data) { data = await this.extractMessages(CAUR_NEWS_ID, 30) - await this.cacheManager.set(cacheKey, data, CACHE_TTL) + await this.cacheManager.set(cacheKey, data, CACHE_TELEGRAM_TTL) } return data } @@ -54,7 +54,7 @@ export class TelegramService { let data: TgMessage[] | undefined = await this.cacheManager.get(cacheKey) if (!data) { data = await this.extractMessages(CAUR_DEPLOY_LOG_ID, parseInt(amount)) - await this.cacheManager.set(cacheKey, data, CACHE_TTL) + await this.cacheManager.set(cacheKey, data, CACHE_TELEGRAM_TTL) } return data } @@ -266,7 +266,7 @@ export class TelegramService { } return extractedMessages }) - await this.cacheManager.set(cacheKey, data, CACHE_TTL) + await this.cacheManager.set(cacheKey, data, CACHE_TELEGRAM_TTL) } return data } diff --git a/frontend/src/app/deploy-log-full/deploy-log-full.component.html b/frontend/src/app/deploy-log-full/deploy-log-full.component.html index 2079f8f2..de31caf4 100644 --- a/frontend/src/app/deploy-log-full/deploy-log-full.component.html +++ b/frontend/src/app/deploy-log-full/deploy-log-full.component.html @@ -3,6 +3,7 @@

Deployment log

Shows the last deployed packages.

Deployment log + diff --git a/frontend/src/app/deploy-log-full/deploy-log-full.component.ts b/frontend/src/app/deploy-log-full/deploy-log-full.component.ts index f26e7f49..a9ebda28 100644 --- a/frontend/src/app/deploy-log-full/deploy-log-full.component.ts +++ b/frontend/src/app/deploy-log-full/deploy-log-full.component.ts @@ -1,11 +1,20 @@ -import { DeploymentList, DeploymentType, getDeployments, parseDeployments } from "@./shared-lib" +import { + CACHE_TELEGRAM_TTL, + DeploymentList, + DeploymentType, + getDeployments, + headToFullDeployments, + parseDeployments, + startShortPolling, +} from "@./shared-lib" import { AfterViewInit, Component } from "@angular/core" import { FormsModule } from "@angular/forms" +import { RouterLink } from "@angular/router" @Component({ selector: "app-deploy-log-full", standalone: true, - imports: [FormsModule], + imports: [FormsModule, RouterLink], templateUrl: "./deploy-log-full.component.html", styleUrl: "./deploy-log-full.component.css", }) @@ -14,17 +23,36 @@ export class DeployLogFullComponent implements AfterViewInit { logAmount: number | undefined requestedTooMany = false currentType: DeploymentType = DeploymentType.ALL + protected readonly headToFullDeployments = headToFullDeployments async ngAfterViewInit(): Promise { void this.updateLogAmount(50) + + // Poll for new deployments every 30 seconds (which is the time the backend caches requests) + startShortPolling(CACHE_TELEGRAM_TTL, async () => { + await this.getNewAmount() + }) } async updateLogAmount(amount: number) { - this.latestDeployments = parseDeployments(await getDeployments(amount, this.currentType), this.currentType) + const newDeployments = parseDeployments(await getDeployments(amount, this.currentType), this.currentType) + + if (newDeployments[0].date !== this.latestDeployments[0].date) { + this.latestDeployments = newDeployments + + // Show if we requested too many deployments + this.requestedTooMany = this.latestDeployments.length < amount + this.constructStrings() - // Show if we requested too many deployments - this.requestedTooMany = this.latestDeployments.length < amount - this.constructStrings() + // Show a notification for a short time + const notification = document.getElementById("toast-deployment") + if (notification) { + notification.classList.remove("invisible") + setTimeout((): void => { + notification.classList.add("invisible") + }, 20000) + } + } } /** diff --git a/frontend/src/app/deploy-log/deploy-log.component.ts b/frontend/src/app/deploy-log/deploy-log.component.ts index e4adbf9a..5d465ad6 100644 --- a/frontend/src/app/deploy-log/deploy-log.component.ts +++ b/frontend/src/app/deploy-log/deploy-log.component.ts @@ -1,4 +1,11 @@ -import { DeploymentList, DeploymentType, getDeployments, parseDeployments } from "@./shared-lib" +import { + CACHE_TELEGRAM_TTL, + DeploymentList, + DeploymentType, + getDeployments, + parseDeployments, + startShortPolling, +} from "@./shared-lib" import { AfterViewInit, Component } from "@angular/core" import { FormsModule } from "@angular/forms" import { RouterLink } from "@angular/router" @@ -18,6 +25,11 @@ export class DeployLogComponent implements AfterViewInit { await getDeployments(30, DeploymentType.SUCCESS), DeploymentType.SUCCESS, ) + + // Poll for new deployments every 5 minutes (which is the time the backend caches requests) + startShortPolling(CACHE_TELEGRAM_TTL, async () => { + await this.checkNewDeployments() + }) } /** @@ -28,15 +40,8 @@ export class DeployLogComponent implements AfterViewInit { await getDeployments(30, DeploymentType.SUCCESS), DeploymentType.SUCCESS, ) - if (newList !== this.latestDeployments) { + if (newList[0].date !== this.latestDeployments[0].date) { this.latestDeployments = newList } } - - /** - * Redirect to the full deployment log. - */ - headToFullDeployments(): void { - window.location.href = "./deploy-log" - } } diff --git a/frontend/src/app/news-channel/news-channel.component.ts b/frontend/src/app/news-channel/news-channel.component.ts index a5a0a892..769085d1 100644 --- a/frontend/src/app/news-channel/news-channel.component.ts +++ b/frontend/src/app/news-channel/news-channel.component.ts @@ -1,4 +1,4 @@ -import { CAUR_TG_API_URL, TgMessageList, checkIfMobile } from "@./shared-lib" +import { CAUR_TG_API_URL, checkIfMobile, TgMessageList } from "@./shared-lib" import { AfterViewInit, Component } from "@angular/core" import { Axios } from "axios" diff --git a/frontend/src/app/stats-page/package-search/package-search.component.ts b/frontend/src/app/stats-page/package-search/package-search.component.ts index 7fb38900..96699d69 100644 --- a/frontend/src/app/stats-page/package-search/package-search.component.ts +++ b/frontend/src/app/stats-page/package-search/package-search.component.ts @@ -25,7 +25,7 @@ export class PackageSearchComponent { } updateDisplay(): void { - if (/^[0-9|a-zA-Z]*$/.test(this.searchPackage)) { + if (/^[0-9|a-zA-Z-]*$/.test(this.searchPackage)) { this.loading = true this.getSpecificPackageMetrics().then((result) => { this.packageMetrics = result diff --git a/frontend/src/app/status/status.component.ts b/frontend/src/app/status/status.component.ts index 6cbf7ae0..d2c169bd 100644 --- a/frontend/src/app/status/status.component.ts +++ b/frontend/src/app/status/status.component.ts @@ -1,4 +1,4 @@ -import { CAUR_API_URL, CurrentQueue, StatsObject } from "@./shared-lib" +import { CAUR_API_URL, CurrentQueue, headToFullDeployments, StatsObject } from "@./shared-lib" import { AfterViewInit, Component } from "@angular/core" import { Axios } from "axios" import { DeployLogComponent } from "../deploy-log/deploy-log.component" @@ -16,6 +16,7 @@ export class StatusComponent implements AfterViewInit { lastUpdated: string | undefined loading = true showFullPackages = false + protected readonly headToFullDeployments = headToFullDeployments ngAfterViewInit(): void { void this.getQueueStats() @@ -81,13 +82,6 @@ export class StatusComponent implements AfterViewInit { }) } - /** - * Redirect to the full deployment log. - */ - headToFullDeployments(): void { - window.location.href = "./deploy-log" - } - /** * Replace currentList with fullList. For people who want to display the full list. */ diff --git a/shared-lib/src/lib/functions.ts b/shared-lib/src/lib/functions.ts index 386d363a..d850c95b 100644 --- a/shared-lib/src/lib/functions.ts +++ b/shared-lib/src/lib/functions.ts @@ -140,3 +140,21 @@ export async function getDeployments(amount: number, type: DeploymentType): Prom console.error(err) }) } + +/** + * Poll for new deployments. + * @param interval + * @param func The function to call. + */ +export function startShortPolling(interval: any, func: () => void): void { + let initialInterval + interval = setInterval(func, interval) + clearInterval(initialInterval) +} + +/** + * Redirect to the full deployment log. + */ +export function headToFullDeployments(): void { + window.location.href = "./deploy-log" +} diff --git a/shared-lib/src/lib/types.ts b/shared-lib/src/lib/types.ts index 6e46773f..191c515b 100644 --- a/shared-lib/src/lib/types.ts +++ b/shared-lib/src/lib/types.ts @@ -9,10 +9,11 @@ export const CAUR_PRIMARY_KEY = "3056513887B78AEB" export const CAUR_TG_API_URL = `${CAUR_BACKEND_URL}/telegram/` export const CAUR_DEPLOY_LOG_ID = "-1002151616973" export const CAUR_NEWS_ID = "-1001293714071" -export const CACHE_TTL = 60 * 5 * 1000 +export const CACHE_ROUTER_TTL = 60 * 5 * 1000 export const CAUR_METRICS_URL = "https://metrics.chaotic.cx/" export const CAUR_ALLOWED_CORS = ["https://aur.chaotic.cx", "https://caur-frontend-pages.dev"] export const CAUR_BACKEND_PORT = 3000 +export const CACHE_TELEGRAM_TTL = 30 * 1000 export type StatsObject = Record< string,