Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ const fallbackListRoute = createRoute({
summary: "List deployments (database fallback)",
tags: ["Deployments"],
security: SECURITY_NONE,
cache: { maxAge: 10, staleWhileRevalidate: 30 },
request: {
query: FallbackDeploymentListQuerySchema
},
Expand Down Expand Up @@ -330,6 +331,7 @@ const fallbackInfoRoute = createRoute({
summary: "Get deployment info (database fallback)",
tags: ["Deployments"],
security: SECURITY_NONE,
cache: { maxAge: 10, staleWhileRevalidate: 30 },
request: {
query: FallbackDeploymentInfoQuerySchema
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { Deployment, DeploymentGroup, DeploymentGroupResource } from "@akashnetw
import { inject, singleton } from "tsyringe";

import { USDC_IBC_DENOMS } from "@src/billing/config/network.config";
import { cacheResponse, Memoize } from "@src/caching/helpers";
import type { CoreConfig } from "@src/core/providers/config.provider";
import { CORE_CONFIG } from "@src/core/providers/config.provider";
import { DeploymentRepository } from "@src/deployment/repositories/deployment/deployment.repository";
import { DatabaseDeploymentListParams } from "@src/deployment/repositories/deployment/deployment.repository";
import { RestAkashDeploymentInfoResponse } from "@src/types/rest/akashDeploymentInfoResponse";
import { RestAkashDeploymentListResponse } from "@src/types/rest/akashDeploymentListResponse";
import { averageBlockTime } from "@src/utils/constants";

export const UNKNOWN_DB_PLACEHOLDER = "unknown_value";

Expand All @@ -23,6 +25,10 @@ export class FallbackDeploymentReaderService {
}

async findAll(params: DatabaseDeploymentListParams): Promise<RestAkashDeploymentListResponse> {
return cacheResponse(averageBlockTime, `FallbackDeploymentReaderService#findAll#${JSON.stringify(params)}`, () => this.findAllUncached(params));
}

private async findAllUncached(params: DatabaseDeploymentListParams): Promise<RestAkashDeploymentListResponse> {
const { skip = 0, limit = 100, key, countTotal = true } = params;

const { count: total, rows: deployments } = await this.deploymentRepository.findDeploymentsWithPagination(params);
Expand Down Expand Up @@ -94,6 +100,7 @@ export class FallbackDeploymentReaderService {
};
}

@Memoize({ ttlInSeconds: averageBlockTime })
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: not sure about the details of @Memoize but it seems that cache key is highly variable, wouldn't it open another point of failure like OOM?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and probably in case of blockchain being available, we could just redirect request to blockchain api

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also we need to find out the reason why pool is exhausted:

  • is this because of slow db query?
  • is this because amount of requests too high?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for the fallback when the chain in unavailable, I think from what I've seen is bursts of queries. But yea this is not a permanent fix for the problem.

async findByOwnerAndDseq(owner: string, dseq: string): Promise<RestAkashDeploymentInfoResponse | null> {
const deployment = await this.deploymentRepository.findByIdWithGroups(owner, dseq);

Expand Down
Loading