fix(CodeFeed): Improve commit fetching concurrency and add tagged-only commit filtering along with updated documentation and tests

This commit is contained in:
2025-04-25 20:56:01 +00:00
parent c639735f92
commit b6af835d3f
5 changed files with 49 additions and 17 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@foss.global/codefeed',
version: '1.7.0',
version: '1.7.1',
description: 'The @foss.global/codefeed module is designed for generating feeds from Gitea repositories, enhancing development workflows by processing commit data and repository activities.'
}

View File

@ -14,6 +14,8 @@ export class CodeFeed {
private cache: plugins.interfaces.ICommitResult[] = [];
// enable or disable npm publishedOnNpm checks (true by default)
private enableNpmCheck: boolean = true;
// return only tagged commits (false by default)
private enableTaggedOnly: boolean = false;
constructor(
baseUrl: string,
@ -23,6 +25,7 @@ export class CodeFeed {
enableCache?: boolean;
cacheWindowMs?: number;
enableNpmCheck?: boolean;
taggedOnly?: boolean;
}
) {
this.baseUrl = baseUrl;
@ -33,6 +36,7 @@ export class CodeFeed {
this.enableCache = options?.enableCache ?? false;
this.cacheWindowMs = options?.cacheWindowMs;
this.enableNpmCheck = options?.enableNpmCheck ?? true;
this.enableTaggedOnly = options?.taggedOnly ?? false;
this.cache = [];
// npm registry instance for version lookups
this.npmRegistry = new plugins.smartnpm.NpmRegistry();
@ -45,7 +49,7 @@ export class CodeFeed {
public async fetchAllCommitsFromInstance(): Promise<plugins.interfaces.ICommitResult[]> {
// Controlled concurrency with AsyncExecutionStack
const stack = new plugins.lik.AsyncExecutionStack();
stack.setNonExclusiveMaxConcurrency(5);
stack.setNonExclusiveMaxConcurrency(20);
// determine since timestamp for this run (stateful caching)
let effectiveSince = this.lastRunTimestamp;
if (this.enableCache && this.cache.length > 0) {
@ -176,9 +180,16 @@ export class CodeFeed {
this.lastRunTimestamp = new Date().toISOString();
// sort descending by timestamp
this.cache.sort((a, b) => b.timestamp.localeCompare(a.timestamp));
// apply tagged-only filter if requested
if (this.enableTaggedOnly) {
return this.cache.filter((c) => c.tagged === true);
}
return this.cache;
}
// otherwise, return only newly fetched commits
// no caching: apply tagged-only filter if requested
if (this.enableTaggedOnly) {
return newResults.filter((c) => c.tagged === true);
}
return newResults;
}