Skip to content

Commit

Permalink
Merge pull request #58 from usherlabs/feat/deduplicate-sqlite
Browse files Browse the repository at this point in the history
fix: handle duplicate stream messages on sqlite gracefully
  • Loading branch information
rsoury authored Jun 8, 2024
2 parents 5c21b7c + 08bbda7 commit 0884df7
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 0884df7

Please sign in to comment.