Skip to content

Commit

Permalink
Fix metadata increment values using actual values to increment by
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiname committed Nov 2, 2023
1 parent 75b3b77 commit 009f282
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
26 changes: 26 additions & 0 deletions packages/node-core/src/indexer/storeCache/cacheMetadata.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import {CacheMetadataModel} from './cacheMetadata';

const incrementKey = 'processedBlockCount';

describe('CacheMetadata', () => {
let cacheMetadata: CacheMetadataModel;

beforeEach(() => {
cacheMetadata = new CacheMetadataModel(null as any);
});

// Clearing the cache used to set the setCache and getCache to the same empty object
// The set cache has increment amounts while the get cache has the actual value
it('clears the caches properly', () => {
cacheMetadata.clear();

(cacheMetadata as any).getCache[incrementKey] = 100;

cacheMetadata.setIncrement(incrementKey);

expect((cacheMetadata as any).setCache[incrementKey]).toBe(1);
});
});
5 changes: 3 additions & 2 deletions packages/node-core/src/indexer/storeCache/cacheMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import assert from 'assert';
import {Transaction} from '@subql/x-sequelize';
import {getLogger} from '../..//logger';
import {hasValue} from '../../utils';
import {Metadata, MetadataKeys, MetadataRepo} from '../entities';
import {Cacheable} from './cacheable';
Expand Down Expand Up @@ -139,7 +140,7 @@ export class CacheMetadataModel extends Cacheable implements ICachedModelControl
newSetCache.lastProcessedHeight = this.setCache.lastProcessedHeight;
this.flushableRecordCounter = 1;
}
this.setCache = newSetCache;
this.getCache = newSetCache;
this.setCache = {...newSetCache};
this.getCache = {...newSetCache};
}
}

0 comments on commit 009f282

Please sign in to comment.