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
26 changes: 0 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"@sinclair/typebox": "^0.34.30",
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
"async-cache-dedupe": "^3.4.0",
"compression": "^1.8.0",
"config": "^3.3.12",
"date-fns": "^4.1.0",
Expand Down
37 changes: 3 additions & 34 deletions src/configs/models/configManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { inject, injectable } from 'tsyringe';
import { Clone } from '@sinclair/typebox/value';
import pointer, { type JsonObject } from 'json-pointer';
import { formatISO, parseISO } from 'date-fns';
import { Cache, createCache } from 'async-cache-dedupe';
import { get } from 'lodash';
import { paths, components } from '@openapi';
import type { Prettify } from '@common/interfaces';
Expand All @@ -36,39 +35,18 @@ type DefaultConfigToInsert = Parameters<ConfigManager['createConfig']>[0] & {
visited: boolean;
};

interface FullConfigMetadataParams {
name: string;
schemaId: string;
version?: number;
}

// Constants for configuration metadata
const MAX_RECURSION_DEPTH = 2;

@injectable()
export class ConfigManager {
private readonly fullConfigCache: Cache & {
getMetadata: (args: FullConfigMetadataParams) => Promise<ConfigFullMetadata>;
};

public constructor(
@inject(SERVICES.LOGGER) private readonly logger: Logger,
@inject(ConfigRepository) private readonly configRepository: ConfigRepository,
@inject(Validator) private readonly configValidator: Validator,
@inject(HashPropagationHelper) private readonly hashPropagationHelper: HashPropagationHelper,
@inject(SchemaManager) private readonly schemaManager: SchemaManager
) {
// Initialize async-cache-dedupe for full config metadata
const cache = createCache({
ttl: 300, // 5 minutes in seconds
storage: { type: 'memory' },
});

// Define cached function for full config metadata
this.fullConfigCache = cache.define('getMetadata', async (params: FullConfigMetadataParams) => {
return this.generateFullConfigMetadata(params.name, params.schemaId, params.version);
});
}
) {}

@withSpan()
public async getConfig(name: string, schemaId: string, version?: number, shouldDereferenceConfig?: boolean): Promise<Config> {
Expand Down Expand Up @@ -803,11 +781,10 @@ export class ConfigManager {
}

/**
* Generate comprehensive config metadata (uncached)
* Internal method used by cached getFullConfigMetadata
* Get comprehensive config metadata for inspector page
*/
@withSpan()
private async generateFullConfigMetadata(name: string, schemaId: string, version?: number): Promise<ConfigFullMetadata> {
public async getFullConfigMetadata(name: string, schemaId: string, version?: number): Promise<ConfigFullMetadata> {
this.logger.info({ msg: 'Generating full config metadata', name, schemaId, version });

// 1. Fetch raw and resolved config in parallel
Expand Down Expand Up @@ -894,12 +871,4 @@ export class ConfigManager {

return metadata;
}

/**
* Get comprehensive config metadata for inspector page (cached)
*/
@withSpan()
public async getFullConfigMetadata(name: string, schemaId: string, version?: number): Promise<ConfigFullMetadata> {
return this.fullConfigCache.getMetadata({ name, schemaId, version });
}
}
23 changes: 0 additions & 23 deletions tests/integration/configs/configs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1476,29 +1476,6 @@ describe('config', function () {
});
});

describe('Caching Behavior', function () {
it('should return consistent results on repeated calls (caching works)', async function () {
// First call
const response1 = await requestSender.getFullConfig({
pathParams: { name: 'config2', version: 1 },
queryParams: { schemaId: 'https://mapcolonies.com/simpleSchema/v1' },
});

expectResponseStatus(response1, 200);

// Second call - should get same result (potentially from cache)
const response2 = await requestSender.getFullConfig({
pathParams: { name: 'config2', version: 1 },
queryParams: { schemaId: 'https://mapcolonies.com/simpleSchema/v1' },
});

expectResponseStatus(response2, 200);

// Verify both responses are identical
expect(response1.body).toStrictEqual(response2.body);
});
});

describe('Complex Scenarios', function () {
it('should handle configs with latest version references correctly', async function () {
// config-ref-3 uses 'latest' version reference
Expand Down
Loading