Added change batches, so clients can catch up on changed opportunities
Every save that stores new opportunities or new releases records them in a change batch (migration 00008: opportunity_change_batches and opportunity_change_batch_opportunities; the opportunities table is unchanged), as does every change of marks. A batch is named by a random SHA-256 hash, so it can't be guessed, and ordered by its created_at, which is kept strictly increasing even if the clock goes back. GET /api/opportunities pages now carry the newest batch, read before the page, and GET /api/opportunities?changed_after=<batch> returns every opportunity changed since that batch, unpaged, with the newest batch it includes. Offset and limit can't be combined with it, and an unknown batch is 410 Gone, telling the client to reload the whole list. OpportunitiesUpdated now carries its save's batch, and a "large" flag: over 50 opportunities, new and updated are left empty and only the summary counts them, so a big catch-up no longer sends tens of thousands of UUIDs.
This commit is contained in:
1 parent
51d6470649
commit
155b84caea
13 files changed
+699
-29
No files matched your search
@@ -15,12 +15,14 @@ func TestOpportunitiesUpdatedPayloadJSON(t *testing.T) {
|
||||
Summary: OpportunitiesSummary{
|
||||
New: 1,
|
||||
},
|
||||
Batch: "abc",
|
||||
}
|
||||
encoded, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := `{"new":["ocds-1"],"updated":[],"summary":{"new":1,"updated":0}}`
|
||||
want := `{"new":["ocds-1"],"updated":[],"large":false,` +
|
||||
`"summary":{"new":1,"updated":0},"batch":"abc"}`
|
||||
if string(encoded) != want {
|
||||
t.Errorf("JSON = %s; want %s", encoded, want)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user