Skip to content

Commit

Permalink
docs: add docs and rename variables for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnigir1 committed Jan 9, 2025
1 parent c3276a3 commit 4885d84
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
16 changes: 8 additions & 8 deletions apps/processing/src/services/sharedDependencies.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ export class SharedDependenciesService {
env.DATABASE_SCHEMA,
);
const pricingRepository = new KyselyPricingCache(kyselyDatabase, env.DATABASE_SCHEMA);
const _pricingProvider = PricingProviderFactory.create(env, {
const pricingProvider = PricingProviderFactory.create(env, {
logger,
});
const pricingProvider = new CachingPricingProvider(
_pricingProvider,
const cachedPricingProvider = new CachingPricingProvider(
pricingProvider,
pricingRepository,
logger,
);

const metadataRepository = new KyselyMetadataCache(kyselyDatabase, env.DATABASE_SCHEMA);
const _metadataProvider = new IpfsProvider(env.IPFS_GATEWAYS_URL, logger);
const metadataProvider = new CachingMetadataProvider(
_metadataProvider,
const metadataProvider = new IpfsProvider(env.IPFS_GATEWAYS_URL, logger);
const cachedMetadataProvider = new CachingMetadataProvider(
metadataProvider,
metadataRepository,
logger,
);
Expand Down Expand Up @@ -118,9 +118,9 @@ export class SharedDependenciesService {
projectRepository,
roundRepository,
applicationRepository,
pricingProvider,
pricingProvider: cachedPricingProvider,
donationRepository,
metadataProvider,
metadataProvider: cachedMetadataProvider,
applicationPayoutRepository,
transactionManager,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ import { Database, handlePostgresError, ICache } from "../../internal.js";

export type PriceCacheKey = { tokenCode: TokenCode; timestampMs: number };

/**
* A cache for token prices using Kysely.
* This cache is used to store and retrieve token prices for a given token and timestamp.
* It uses the `priceCache` table in the database to store the prices.
* Note: no eviction strategy is implemented since is not needed for the current use case.
*/
export class KyselyPricingCache implements ICache<PriceCacheKey, TokenPrice> {
constructor(
private readonly db: Kysely<Database>,
private readonly schema: string,
) {}

/** @inheritdoc */
async get(key: { tokenCode: TokenCode; timestampMs: number }): Promise<TokenPrice | undefined> {
const { tokenCode, timestampMs } = key;

Expand Down

0 comments on commit 4885d84

Please sign in to comment.