From 44c3eb014fecf4ac81b5ba4d5704ea4a9789e9fe Mon Sep 17 00:00:00 2001 From: Kathleen Tuite Date: Wed, 25 Sep 2024 10:46:13 -0700 Subject: [PATCH] Updating interrupted branch count query --- lib/model/query/analytics.js | 5 +-- test/integration/other/analytics-queries.js | 36 ++++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/lib/model/query/analytics.js b/lib/model/query/analytics.js index 306c8430b..1088ac1df 100644 --- a/lib/model/query/analytics.js +++ b/lib/model/query/analytics.js @@ -496,7 +496,7 @@ WITH sortedRows AS ( "entityId", "version", "branchId", - LAG("branchId") OVER (PARTITION BY "entityId" ORDER BY "version") AS prevBranchId + LAG("branchId") OVER (PARTITION BY "entityId" ORDER BY "version") AS "prevBranchId" FROM entity_defs ), distinctRuns AS ( @@ -504,7 +504,7 @@ distinctRuns AS ( "entityId", "branchId" FROM sortedRows - WHERE "branchId" != prevBranchId OR prevBranchId IS NULL -- Keep first row and changes + WHERE "version" = 1 OR "branchId" IS DISTINCT FROM "prevBranchId" -- Keep first row and changes ), duplicateRuns AS ( SELECT @@ -512,6 +512,7 @@ duplicateRuns AS ( "branchId", COUNT(*) AS runCount FROM distinctRuns + WHERE "branchId" IS NOT NULL GROUP BY "entityId", "branchId" HAVING COUNT(*) > 1 -- Selects branchIds that occur more than once ) diff --git a/test/integration/other/analytics-queries.js b/test/integration/other/analytics-queries.js index 67a0069bd..fa5d434c1 100644 --- a/test/integration/other/analytics-queries.js +++ b/test/integration/other/analytics-queries.js @@ -1425,6 +1425,7 @@ describe('analytics task queries', function () { { uuid: '12345678-1234-4123-8234-123456789aaa', label: 'aaa' }, { uuid: '12345678-1234-4123-8234-123456789bbb', label: 'bbb' }, { uuid: '12345678-1234-4123-8234-123456789ccc', label: 'ccc' }, + { uuid: '12345678-1234-4123-8234-123456789ddd', label: 'ddd' }, ], source: { name: 'api', size: 3 } }) @@ -1555,8 +1556,41 @@ describe('analytics task queries', function () { await exhaust(container); + // ddd entity, branches A, (api update), A + const dddBranchA = uuid(); + await asAlice.post('/v1/projects/1/forms/offlineEntity/submissions') + .send(testData.instances.offlineEntity.one + .replace('id="12345678-1234-4123-8234-123456789abc', 'id="12345678-1234-4123-8234-123456789ddd') + .replace('one', 'ddd-v1') + .replace('branchId=""', `branchId="${dddBranchA}"`) + ) + .set('Content-Type', 'application/xml') + .expect(200); + + await exhaust(container); + + await asAlice.patch('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789ddd?baseVersion=2') + .send({ label: 'ddd update' }) + .expect(200); + + await asAlice.patch('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789ddd?baseVersion=3') + .send({ label: 'ddd update2' }) + .expect(200); + + await asAlice.post('/v1/projects/1/forms/offlineEntity/submissions') + .send(testData.instances.offlineEntity.one + .replace('id="12345678-1234-4123-8234-123456789abc', 'id="12345678-1234-4123-8234-123456789ddd') + .replace('one', 'ddd-v2') + .replace('baseVersion="1"', 'baseVersion="2"') + .replace('branchId=""', `branchId="${dddBranchA}"`) + ) + .set('Content-Type', 'application/xml') + .expect(200); + + await exhaust(container); + const countInterruptedBranches = await container.Analytics.countInterruptedBranches(); - countInterruptedBranches.should.equal(3); + countInterruptedBranches.should.equal(4); })); it('should count number of submission.reprocess events (submissions temporarily in the backlog)', testService(async (service, container) => {