Question about "Last" index returned by /changes when "since" parameter is large

Hi,

I have a question about “Last” as returned by the /changes endpoint in current Orthanc (v1.2.0, with postgres plugin).

Currently, if Changes is empty (if since is larger than the maximum change index), then Last will always [1] be equal to since.

% curl “http://orthanc.example/changes?last
{
“Changes” : [ { …, “Seq” : 501 } ],
“Done” : true,
“Last” : 501
}

% curl “http://orthanc.example/changes?since=1000” # returns ‘“Last”: 1000’, not ‘“Last”: 501’
{
“Changes” : [],
“Done” : true,
“Last” : 1000
}

I had expected Last to never return anything larger than the maximum change index (501).

I have a simple script that processes all events in an Orthanc installation in the following way:

  • it watches /changes and pages through all results, processing events as it goes.
  • when it gets to the end ({Done: true}), it:
  • stores Last as last_index
  • waits for a few seconds
  • calls /chances?since=last_index until there are results again.

Current Orthanc behaviour can break this, because when someone runs DELETE /changes or when everything in the database gets removed (this is for an Orthanc installation that does routing), the maximum change index can sometimes decrease.

However, because Last still returns whatever I am sending in since, my script will not notice this and therefore miss later updates.

I am working around this now by calling /changes?last whenever the returned list of changes is empty. (and taking whatever index is smaller to avoid race conditions) - This seems a bit hacky though and I’d prefer not to need to do this.

Would you consider a change of this behaviour? Is there maybe another way for API clients to notice that the change index they are using is no longer valid?

Thank you,
Levin

[1] barring integer overflows

Hello,

Back to this very old thread from 2017, this behavior was improved as part of Orthanc 1.5.2 by the following changeset:
https://hg.orthanc-server.com/orthanc/rev/3105

Here is an example on our demo server:

$ curl https://demo.orthanc-server.com/changes?last
{
“Changes” : [ <…> ],
“Done” : true,
“Last” : 2843
}
$ curl https://demo.orthanc-server.com/changes**?since=10000**
{
“Changes” : [],
“Done” : true,
“Last” : 2843
}

As can be seen, the “Last” field now works as you expected.

Regards,
Sébastien-