-
Notifications
You must be signed in to change notification settings - Fork 128
Add an index and revise a select related to deleting all shots #3629
Add an index and revise a select related to deleting all shots #3629
Conversation
It is possible to load up your local database some, with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not confident that this will fix the query.
But, we now store the accountid in req.accountId
, and have changed a bunch of these queries to be something like Shot.deleteEverythingForDevice = function(backend, deviceId, accountId) {...}
, and then if accountId is not null/undefined, we use that to query for all the other deviceIds we should delete.
Hmm I was only optimizing against Postgres's It deletes the image data for a given @ianb Are you suggesting that (a) we delete all images for an account if |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deviceIdSelect/promise part should be changed a bit
server/src/servershot.js
Outdated
WHERE devices.accountid = $1`, | ||
[accountId]); | ||
} else { | ||
deviceIdsSelect = db.select( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case we know exactly what the deviceIds will be: [deviceId]
. So probably what it should be is something like:
if (accountId) {
deviceIdsSelect = db.select(...).then((rows) => {
return rows.map((row) => row.deviceId);
});
} else {
deviceIdsSelect = Promise.resolve([deviceId]);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify/confirm: this changes the previous behavior when shots of one device is deleted, if the device is associated to an account (but not authenticated thus no accountId
), then the shots of the other devices that are associated to that account will also be deleted. After this patch, only the shots of the given device will be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really? That doesn't seem like what I'm reading here. This query seems to get images from all devices:
return db.select(
`SELECT images.id
FROM images JOIN data
ON images.shotid = data.id
WHERE data.deviceid IN (${db.markersForArgs(1, deviceIds.length)})`,
deviceIds);
Or at least all devices listed in deviceIds...?
Note the change I'm proposing is that when accountId is null (and so there are no other devices), then we just use deviceIds = [deviceId]
(more or less)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are reading that query correctly. But if we use deviceIds = [deviceId]
, then there's only one device id in IN
. Currently, the device ids come from https://github.com/mozilla-services/screenshots/blob/master/server/src/servershot.js#L634 regardless of the user's authentication state, and that could returns multiple device ids.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If accountId is null then devices.accountid is also null, and there aren't any associated devices. At login or account connect time we set accountid, so we can trust that if it's null then there aren't any other associated deviceIds.
Would be nice to get some before and after numbers on an environment with a lot of data.
Fix #3568