Skip to content

Commit

Permalink
feat(bundles): increment import_attempt_count when skipping bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
karlprieb authored and djwhitt committed Jan 23, 2025
1 parent 1697b90 commit 83b02a8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/database/sql/bundles/import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ INSERT INTO bundles (
@skipped_at, @skipped_at,
@unbundled_at, @unbundled_at,
@fully_indexed_at, @fully_indexed_at,
CASE WHEN @queued_at IS NOT NULL THEN 1 ELSE 0 END,
CASE WHEN (@queued_at IS NOT NULL OR @skipped_at IS NOT NULL) THEN 1 ELSE 0 END,
@duplicated_data_item_count
) ON CONFLICT DO UPDATE SET
data_item_count = IFNULL(@data_item_count, data_item_count),
Expand All @@ -33,7 +33,7 @@ INSERT INTO bundles (
first_fully_indexed_at = IFNULL(first_fully_indexed_at, @fully_indexed_at),
last_fully_indexed_at = @fully_indexed_at,
import_attempt_count = CASE
WHEN @queued_at IS NOT NULL THEN
WHEN (@queued_at IS NOT NULL OR @skipped_at IS NOT NULL) THEN
COALESCE(bundles.import_attempt_count, 0) + 1
ELSE
bundles.import_attempt_count
Expand Down
80 changes: 67 additions & 13 deletions src/database/standalone-sqlite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,7 @@ describe('StandaloneSqliteDatabase', () => {
describe('saveBundle', () => {
const id0 = '0000000000000000000000000000000000000000000';
const id1 = '1111111111111111111111111111111111111111111';
const id2 = '2222222222222222222222222222222222222222222';

const bundle: BundleRecord = {
id: id0,
Expand All @@ -1012,6 +1013,12 @@ describe('StandaloneSqliteDatabase', () => {
matchedDataItemCount: 2,
};

const sql = `
SELECT *
FROM bundles
WHERE id = @id
`;

beforeEach(async () => {
await db.saveBundle(bundle);
await db.saveBundle({
Expand All @@ -1020,6 +1027,11 @@ describe('StandaloneSqliteDatabase', () => {
queuedAt: 1234567890,
duplicatedDataItemCount: 1,
});
await db.saveBundle({
...bundle,
id: id2,
skippedAt: 1234567890,
});
});

it('should insert into bundles', async () => {
Expand All @@ -1032,32 +1044,74 @@ describe('StandaloneSqliteDatabase', () => {
assert.equal(bundlesDb.prepare(sql).get({ id: fromB64Url(id0) }).cnt, 1);
});

it('should set import_attempt_count 0 when no queuedAt is provided', async () => {
const sql = `
SELECT *
FROM bundles
WHERE id = @id
`;

it('should set import_attempt_count 0 when no queuedAt or skippedAt is provided', async () => {
assert.equal(
bundlesDb.prepare(sql).get({ id: fromB64Url(id0) })
.import_attempt_count,
0,
);
});

it('should set import_attempt_count 1 when queuedAt is provided', async () => {
const sql = `
SELECT *
FROM bundles
WHERE id = @id
`;
it('should set import_attempt_count 1 when queuedAt or skippedAt is provided', async () => {
assert.equal(
bundlesDb.prepare(sql).get({ id: fromB64Url(id1) })
.import_attempt_count,
1,
);

assert.equal(
bundlesDb.prepare(sql).get({ id: fromB64Url(id2) })
.import_attempt_count,
1,
);
});

it("shouldn't increment import_attempt_count when no queuedAt or skippedAt", async () => {
await db.saveBundle({
...bundle,
id: id1,
});
await db.saveBundle({
...bundle,
id: id2,
});

assert.equal(
bundlesDb.prepare(sql).get({ id: fromB64Url(id1) })
.import_attempt_count,
1,
);

assert.equal(
bundlesDb.prepare(sql).get({ id: fromB64Url(id2) })
.import_attempt_count,
1,
);
});

it('should increment import_attempt_count when queuedAt or skippedAt is provided', async () => {
await db.saveBundle({
...bundle,
id: id1,
queuedAt: 1234567890,
});
await db.saveBundle({
...bundle,
id: id2,
skippedAt: 1234567890,
});

assert.equal(
bundlesDb.prepare(sql).get({ id: fromB64Url(id1) })
.import_attempt_count,
2,
);

assert.equal(
bundlesDb.prepare(sql).get({ id: fromB64Url(id2) })
.import_attempt_count,
2,
);
});
});

Expand Down

0 comments on commit 83b02a8

Please sign in to comment.