1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: force updated_at date to change (#9092)

This commit is contained in:
Mateusz Kwasniewski 2025-01-13 15:51:29 +01:00 committed by GitHub
parent fea3d89fca
commit 1b4d1df84f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import type {
IUnleashStores, IUnleashStores,
} from '../../../lib/types'; } from '../../../lib/types';
import HyperLogLog from 'hyperloglog-lite'; import HyperLogLog from 'hyperloglog-lite';
import { isAfter } from 'date-fns';
let stores: IUnleashStores; let stores: IUnleashStores;
let db: ITestDb; let db: ITestDb;
@ -56,3 +57,23 @@ test('should indicate when no entry', async () => {
expect(fetchedHll).toBeNull(); expect(fetchedHll).toBeNull();
}); });
test('should update updated_at date', async () => {
const hll = HyperLogLog(12);
hll.add(HyperLogLog.hash('connection-1'));
hll.add(HyperLogLog.hash('connection-2'));
await uniqueConnectionStore.insert({
id: 'current',
hll: hll.output().buckets,
});
const firstFetch = await uniqueConnectionStore.get('current');
await uniqueConnectionStore.insert({
id: 'current',
hll: hll.output().buckets,
});
const secondFetch = await uniqueConnectionStore.get('current');
expect(isAfter(secondFetch?.updatedAt!, firstFetch?.updatedAt!)).toBe(true);
});

View File

@ -1,6 +1,7 @@
import type { Db } from '../../db/db'; import type { Db } from '../../db/db';
import type { IUniqueConnectionStore } from '../../types'; import type { IUniqueConnectionStore } from '../../types';
import type { UniqueConnections } from './unique-connection-store-type'; import type { UniqueConnections } from './unique-connection-store-type';
import type { Knex } from 'knex';
export class UniqueConnectionStore implements IUniqueConnectionStore { export class UniqueConnectionStore implements IUniqueConnectionStore {
private db: Db; private db: Db;
@ -10,8 +11,14 @@ export class UniqueConnectionStore implements IUniqueConnectionStore {
} }
async insert(uniqueConnections: UniqueConnections): Promise<void> { async insert(uniqueConnections: UniqueConnections): Promise<void> {
await this.db<UniqueConnections>('unique_connections') await this.db<UniqueConnections & { updated_at: Knex.Raw<any> }>(
.insert({ id: uniqueConnections.id, hll: uniqueConnections.hll }) 'unique_connections',
)
.insert({
id: uniqueConnections.id,
hll: uniqueConnections.hll,
updated_at: this.db.raw('DEFAULT'),
})
.onConflict('id') .onConflict('id')
.merge(); .merge();
} }