Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apps/api/scripts/buildAkashTemplatesCache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import "reflect-metadata";
import "@akashnetwork/env-loader";

import { TemplateGalleryService } from "../src/services/external/templates/template-gallery.service";
import { LoggerService } from "@akashnetwork/logging";
import { promises as fsp } from "node:fs";

import { TemplateGalleryService } from "../src/template/services/template-gallery/template-gallery.service";
import { dataFolderPath } from "../src/utils/constants";

console.log("Warming up Akash templates cache...");
Expand All @@ -10,7 +14,7 @@ if (!githubPAT) {
process.exit(1);
}

const templateGalleryService = new TemplateGalleryService({
const templateGalleryService = new TemplateGalleryService(LoggerService.forContext("TemplateGalleryService.script"), fsp, {
githubPAT,
dataFolderPath,
categoryProcessingConcurrency: 30,
Expand Down
16 changes: 16 additions & 0 deletions apps/api/src/caching/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,19 @@ export const cacheKeys = {
getGpuUtilization: "getGpuUtilization",
getGpuBreakdown: "getGpuBreakdown"
};

export function reusePendingPromise<T extends (...args: any[]) => Promise<unknown>>(fn: T, options?: { getKey?: (...args: Parameters<T>) => string }): T {
const pendingPromises = new Map<string, Promise<unknown>>();

return ((...args: Parameters<T>) => {
const key = options?.getKey ? options.getKey(...args) : JSON.stringify(args);

let pendingPromise = pendingPromises.get(key);
if (!pendingPromise) {
pendingPromise = fn(...args).finally(() => pendingPromises.delete(key)) as ReturnType<T>;
pendingPromises.set(key, pendingPromise);
}

return pendingPromise as ReturnType<T>;
}) as unknown as T;
}
13 changes: 0 additions & 13 deletions apps/api/src/services/external/githubService.ts

This file was deleted.

124 changes: 0 additions & 124 deletions apps/api/src/services/external/templates/template-gallery.service.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
import assert from "http-assert";
import { promises as fsp } from "node:fs";
import { inject, singleton } from "tsyringe";

import { TemplateGalleryService } from "@src/services/external/templates/template-gallery.service";
import { LoggerService } from "@src/core";
import { GetTemplatesListResponseSchema } from "@src/template/http-schemas/template.schema";
import { TEMPLATE_CONFIG, type TemplateConfig } from "@src/template/providers/config.provider";
import { dataFolderPath } from "@src/utils/constants";
import { TemplateGalleryService } from "../../services/template-gallery/template-gallery.service";

@singleton()
export class TemplateController {
private readonly templateGalleryService: TemplateGalleryService;

constructor(@inject(TEMPLATE_CONFIG) templateConfig: TemplateConfig) {
this.templateGalleryService = new TemplateGalleryService({
constructor(@inject(TEMPLATE_CONFIG) templateConfig: TemplateConfig, logger: LoggerService) {
logger.setContext(TemplateGalleryService.name);
this.templateGalleryService = new TemplateGalleryService(logger, fsp, {
githubPAT: templateConfig.GITHUB_PAT,
dataFolderPath
});
}

async getTemplatesFull() {
return await this.templateGalleryService.getTemplateGallery();
const result = await this.templateGalleryService.getTemplateGallery();
return result.categories;
}

async getTemplatesList() {
const templatesPerCategory = await this.templateGalleryService.getTemplateGallery();
// TODO: remove manual response filtering when https://github.com/honojs/middleware/issues/181 is done
const arraySchema = GetTemplatesListResponseSchema.pick({ data: true }).shape.data;
const filteredTemplatesPerCategory = await arraySchema.safeParseAsync(templatesPerCategory);
const response = filteredTemplatesPerCategory.success ? filteredTemplatesPerCategory.data : templatesPerCategory;
const filteredTemplatesPerCategory = await arraySchema.safeParseAsync(templatesPerCategory.categories);
const response = filteredTemplatesPerCategory.success ? filteredTemplatesPerCategory.data : templatesPerCategory.categories;

return { data: response };
}
Expand Down
Loading
Loading