Skip to content

Commit

Permalink
Ignore duplicate messages in SQLiteDBAdapter
Browse files Browse the repository at this point in the history
The SQLiteDBAdapter now includes an 'onConflictDoNothing' statement during record insertion to handle duplicate messages. Additionally, a test behavior has been implemented to verify that duplicate messages are disregarded.
  • Loading branch information
outerlook committed Jun 7, 2024
1 parent 5c21b7c commit 08bbda7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export class SQLiteDBAdapter extends DatabaseAdapter {
payload: payload,
content_bytes: payload.length,
};
await this.dbClient.insert(streamDataTable).values(record);
await this.dbClient.insert(streamDataTable).values(record).onConflictDoNothing();

this.emit('write', record.payload);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ describe('SQLite', () => {
await testDb.store(createMockMessage(1));
});

test('duplicate messages are ignored', async () => {
const testDb = new SQLiteDBAdapter({ type: 'sqlite', dataPath: dbPath });
await testDb.store(createMockMessage(1));
await testDb.store(createMockMessage(1));
// try querying more than necessary
const stream = testDb.queryLast(MOCK_STREAM_ID, MOCK_PARTITION, 5);
const contentValues = await streamToContentValues(stream);
// there should be only one message
expect(contentValues).toEqual([1, 0]);
})

describe('methods test', () => {
let db: SQLiteDBAdapter;

Expand Down

0 comments on commit 08bbda7

Please sign in to comment.