Use app ts to determine whether to refetch app

This commit is contained in:
Girish Ramakrishnan
2018-06-26 19:07:34 -07:00
parent 3f9f1480d3
commit 3bb82d5e68

View File

@@ -127,6 +127,7 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
memory: 0
};
this._installedApps = [];
this._installedAppsById = {};
this._clientId = '<%= oauth.clientId %>';
this._clientSecret = '<%= oauth.clientSecret %>';
// window.location fallback for websocket connections which do not have relative uris
@@ -1126,6 +1127,8 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
var loc = binarySearch(this._installedApps, function (item) { return item.fqdn.localeCompare(app.fqdn) <= 0; });
this._installedApps.splice(loc, 0, tmp); // insert into sorted fqdn array
}
this._installedAppsById[app.id] = this._installedApps[found];
};
// this requires app:manage permissions
@@ -1151,20 +1154,25 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
this.getApps(function (error, apps) {
if (error) return callback(error);
asyncForEach(apps, function (app, iteratorDone) {
asyncForEach(apps, function (app, iteratorCallback) {
var canManageApp = that.hasScope('apps:manage'); // this can become per app level later
if (!canManageApp) {
that._updateAppCache(app);
return iteratorDone();
return iteratorCallback();
}
that.refreshAppCache(app.id, iteratorDone);
}, function (error) {
if (that._installedAppsById[app.id] && that._installedAppsById[app.id].ts === app.ts) return iteratorCallback(); // app has not changed
that.refreshAppCache(app.id, iteratorCallback);
}, function iteratorDone(error) {
if (error) return callback(error);
// filter out old apps, going backwards to allow splicing
for(var i = that._installedApps.length - 1; i >= 0; --i) {
for (var i = that._installedApps.length - 1; i >= 0; --i) {
if (!apps.some(function (elem) { return (elem.id === that._installedApps[i].id); })) {
that._installedApps.splice(i, 1);
var removed = that._installedApps.splice(i, 1);
delete that._installedAppsById[removed[0].id];
}
}