Skip to content

Commit

Permalink
Optimized loading of most-recent studies when the Orthanc DB supports…
Browse files Browse the repository at this point in the history
… ExtendedChanges
  • Loading branch information
amazy committed Sep 23, 2024
1 parent dc23780 commit 6dbd47e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
34 changes: 26 additions & 8 deletions WebApplication/src/components/StudyList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ export default {
studiesIds: state => state.studies.studiesIds,
selectedStudiesIds: state => state.studies.selectedStudiesIds,
isSearching: state => state.studies.isSearching,
statistics: state => state.studies.statistics
statistics: state => state.studies.statistics,
}),
...mapGetters([
'studies/isFilterEmpty', // -> this['studies/isFilterEmpty']
'studies/isFilterEmpty', // -> this['studies/isFilterEmpty']
'configuration/hasExtendedChanges', // -> this['configuration/hasExtendedChanges']
]),
notShowingAllResults() {
if (this.sourceType == SourceType.LOCAL_ORTHANC) {
Expand Down Expand Up @@ -663,7 +664,7 @@ export default {
this.isLoadingLatestStudies = true;
this.isDisplayingLatestStudies = false;
this.loadStudiesFromChange(Math.max(0, lastChangeId - 1000), 1000);
this.loadStudiesFromChange(lastChangeId, 1000);
}
} else {
this.shouldStopLoadingLatestStudies = true;
Expand All @@ -673,9 +674,18 @@ export default {
await this.$store.dispatch('studies/reloadFilteredStudies');
}
},
async loadStudiesFromChange(fromChangeId, limit) {
let changes = await api.getChanges(fromChangeId, limit);
for (let change of changes["Changes"].reverse()) {
async loadStudiesFromChange(toChangeId, limit) {
let changes;
let changesResponse;
if (this['configuration/hasExtendedChanges']) {
changesResponse = await api.getChangesExtended(toChangeId, limit, ["NewStudy", "StableStudy"]);
changes = changesResponse["Changes"];
} else {
changesResponse = await api.getChanges(toChangeId - limit, limit);
changes = changesResponse["Changes"].reverse();
}
for (let change of changes) {
// Take the first event we find -> we see last uploaded data immediately (NewStudy but no StableStudy).
// An updated study that has received a new series is visible as well (its NewStudy might be too old but the StableStudy brings it back on top of the list)
if ((change["ChangeType"] == "NewStudy" || change["ChangeType"] == "StableStudy") && !this.latestStudiesIds.has(change["ID"])) {
Expand All @@ -701,8 +711,16 @@ export default {
}
}
if (!this.shouldStopLoadingLatestStudies) {
if (fromChangeId > 0 && this.latestStudiesIds.size < this.statistics.CountStudies) {
setTimeout(() => {this.loadStudiesFromChange(Math.max(0, Math.max(0, fromChangeId - 1000)), 1000)}, 1);
if (this.latestStudiesIds.size < this.statistics.CountStudies) {
if (this['configuration/hasExtendedChanges']) {
if (!changesResponse["Done"]) {
setTimeout(() => {this.loadStudiesFromChange(changesResponse["First"], 1000)}, 1);
}
} else {
if (toChangeId != changesResponse["First"]) {
setTimeout(() => {this.loadStudiesFromChange(Math.max(0, toChangeId-1000), 1000)}, 1);
}
}
} else {
this.isLoadingLatestStudies = false;
this.isDisplayingLatestStudies = true;
Expand Down
8 changes: 8 additions & 0 deletions WebApplication/src/orthancApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ export default {
const response = (await axios.get(orthancApiUrl + "changes?since=" + since + "&limit=" + limit));
return response.data;
},
async getChangesExtended(to, limit, filter = []) {
let url = orthancApiUrl + "changes?to=" + to + "&limit=" + limit;
if (filter.length > 0) {
url += "&type=" + filter.join(";")
}
const response = (await axios.get(url));
return response.data;
},
async getSamePatientStudies(patientTags, tags) {
if (!tags || tags.length == 0) {
console.error("Unable to getSamePatientStudies if 'tags' is not defined or empty");
Expand Down
15 changes: 15 additions & 0 deletions WebApplication/src/store/modules/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ const state = () => ({

///////////////////////////// GETTERS
const getters = {
hasExtendedFind: (state) => {
if ("Capabilities" in state.system){
return state.system.Capabilities.HasExtendedFind;
} else {
return false;
}
},
hasExtendedChanges: (state) => {
if ("Capabilities" in state.system){
return state.system.Capabilities.HasExtendedChanges;
} else {
return false;
}

}
}

///////////////////////////// MUTATIONS
Expand Down
6 changes: 6 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Pending changes in the mainline
===============================

Changes:
- Optimized loading of "most-recent" studies when the Orthanc DB supports "ExtendedChanges"

1.6.2 (2024-09-23)
==================

Expand Down

0 comments on commit 6dbd47e

Please sign in to comment.