Skip to content

Commit

Permalink
fix: force updated_at date to change (#9092)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Jan 13, 2025
1 parent fea3d89 commit 1b4d1df
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
IUnleashStores,
} from '../../../lib/types';
import HyperLogLog from 'hyperloglog-lite';
import { isAfter } from 'date-fns';

let stores: IUnleashStores;
let db: ITestDb;
Expand Down Expand Up @@ -56,3 +57,23 @@ test('should indicate when no entry', async () => {

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);
});
11 changes: 9 additions & 2 deletions src/lib/features/unique-connection/unique-connection-store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Db } from '../../db/db';
import type { IUniqueConnectionStore } from '../../types';
import type { UniqueConnections } from './unique-connection-store-type';
import type { Knex } from 'knex';

export class UniqueConnectionStore implements IUniqueConnectionStore {
private db: Db;
Expand All @@ -10,8 +11,14 @@ export class UniqueConnectionStore implements IUniqueConnectionStore {
}

async insert(uniqueConnections: UniqueConnections): Promise<void> {
await this.db<UniqueConnections>('unique_connections')
.insert({ id: uniqueConnections.id, hll: uniqueConnections.hll })
await this.db<UniqueConnections & { updated_at: Knex.Raw<any> }>(
'unique_connections',
)
.insert({
id: uniqueConnections.id,
hll: uniqueConnections.hll,
updated_at: this.db.raw('DEFAULT'),
})
.onConflict('id')
.merge();
}
Expand Down

0 comments on commit 1b4d1df

Please sign in to comment.