diff --git a/lib/util/github/graphql/cache-strategies/abstract-cache-strategy.ts b/lib/util/github/graphql/cache-strategies/abstract-cache-strategy.ts index 26d75d8d54c358abb2afdc71ab2c8916d0819e70..3e2de9f2898e1214f2a423893dcb7b37ce06280b 100644 --- a/lib/util/github/graphql/cache-strategies/abstract-cache-strategy.ts +++ b/lib/util/github/graphql/cache-strategies/abstract-cache-strategy.ts @@ -101,7 +101,6 @@ export abstract class AbstractGithubGraphqlCacheStrategy< const oldItem = cachedItems[version]; if (oldItem && this.isStabilized(oldItem)) { isPaginationDone = true; - break; } cachedItems[version] = item; diff --git a/lib/util/github/graphql/cache-strategies/memory-cache-strategy.spec.ts b/lib/util/github/graphql/cache-strategies/memory-cache-strategy.spec.ts index 1e725e36c5b4c4301ac87f2db697369c74c3ecfa..a5479a547a7db64b3a0d1bfa5930e36effbfeb1c 100644 --- a/lib/util/github/graphql/cache-strategies/memory-cache-strategy.spec.ts +++ b/lib/util/github/graphql/cache-strategies/memory-cache-strategy.spec.ts @@ -127,6 +127,43 @@ describe('util/github/graphql/cache-strategies/memory-cache-strategy', () => { expect(isPaginationDone).toBe(true); }); + it('reconciles entire page', async () => { + const oldItems = { + '1': { releaseTimestamp: isoTs('2020-01-01 00:00'), version: '1' }, + '2': { releaseTimestamp: isoTs('2020-01-01 01:00'), version: '2' }, + '3': { releaseTimestamp: isoTs('2020-01-01 02:00'), version: '3' }, + }; + const cacheRecord: CacheRecord = { + items: oldItems, + createdAt: isoTs('2022-12-31 12:00'), + updatedAt: isoTs('2022-12-31 12:00'), + }; + memCache.set('github-graphql-cache:foo:bar', clone(cacheRecord)); + + const now = '2022-12-31 23:59'; + mockTime(now); + + const page = [ + { version: '1', releaseTimestamp: isoTs('2022-12-31 10:00') }, + { version: '2', releaseTimestamp: isoTs('2022-12-31 11:00') }, + { version: '3', releaseTimestamp: isoTs('2022-12-31 12:00') }, + { version: '4', releaseTimestamp: isoTs('2022-12-31 13:00') }, + ].reverse(); + + const strategy = new GithubGraphqlMemoryCacheStrategy('foo', 'bar'); + const isPaginationDone = await strategy.reconcile(page); + + expect(isPaginationDone).toBe(true); + expect(memCache.get('github-graphql-cache:foo:bar')).toMatchObject({ + items: { + '1': { releaseTimestamp: isoTs('2022-12-31 10:00') }, + '2': { releaseTimestamp: isoTs('2022-12-31 11:00') }, + '3': { releaseTimestamp: isoTs('2022-12-31 12:00') }, + '4': { releaseTimestamp: isoTs('2022-12-31 13:00') }, + }, + }); + }); + it('detects removed packages', async () => { const items = { // stabilized