Fix appdb get query

the get() query was wrong when we had multiple port bindings.

we did apps JOIN X JOIN Y JOIN Z. This will return apps times x times y times z rows.
this just accidentally worked in the past. when we have multiple mounts,
we get duplicate values now.

the fix is do the joins separately and then merge them together.

an alternate approach to this mega query is to SET TRANSACTION SERIALIZABLE and do
multiple selects. but that requires database.js support which is a bit of work (and not
sure how it works with "connections").
This commit is contained in:
Girish Ramakrishnan
2020-11-22 16:01:51 -08:00
parent ef287d4436
commit a8928d26d1
2 changed files with 14 additions and 70 deletions

View File

@@ -6,7 +6,6 @@ exports = module.exports = {
removeRestrictedFields,
get,
getByContainerId,
getByIpAddress,
getByFqdn,
getAll,
@@ -508,24 +507,6 @@ function get(appId, callback) {
});
}
function getByContainerId(containerId, callback) {
assert.strictEqual(typeof containerId, 'string');
assert.strictEqual(typeof callback, 'function');
getDomainObjectMap(function (error, domainObjectMap) {
if (error) return callback(error);
appdb.getByContainerId(containerId, function (error, app) {
if (error && error.reason === BoxError.NOT_FOUND) return callback(new BoxError(BoxError.NOT_FOUND, 'No such app'));
if (error) return callback(error);
postProcess(app, domainObjectMap);
callback(null, app);
});
});
}
// returns the app associated with this IP (app or scheduler)
function getByIpAddress(ip, callback) {
assert.strictEqual(typeof ip, 'string');