Don't do a subquery in a subquery in a subquery.

This was there as a workaround for #1, but that has subsequently
been fixed. Thus, the hack is no longer required. Also removed an
additional `AND` because it is already performed in the `JOIN`.
I supsect this last one would've been eliminated by the sqlite
optimizer anyway, but the query is slightly simpler now.

This fix doesn't improve performance as much as I'd hoped, but it
is something.
This commit is contained in:
Peter Serwylo 2016-04-24 20:09:14 +10:00
parent 7a880fdc33
commit ab248525e0

View File

@ -1057,20 +1057,7 @@ public class AppProvider extends FDroidProvider {
" JOIN " + repo + " ON (" + repo + "._id = " + apk + ".repo) " + " JOIN " + repo + " ON (" + repo + "._id = " + apk + ".repo) " +
" WHERE " + " WHERE " +
app + ".id = " + apk + ".id AND " + app + ".id = " + apk + ".id AND " +
apk + ".vercode = ( " + apk + ".vercode = " + app + ".suggestedVercode ";
// We only want the latest apk here. Ideally, we should
// instead join onto apk.suggestedVercode, but as per
// https://gitlab.com/fdroid/fdroidclient/issues/1 there
// may be some situations where suggestedVercode isn't
// set.
// TODO: If we can guarantee that suggestedVercode is set,
// then join onto that instead. This will save from doing
// a futher sub query for each app.
" SELECT MAX(inner_apk.vercode) " +
" FROM " + apk + " as inner_apk " +
" WHERE inner_apk.id = " + apk + ".id ) " +
" AND " + apk + ".repo = fdroid_repo._id ";
return return
" UPDATE " + app + " SET " + " UPDATE " + app + " SET " +