Calc suggested versioncode properly, regardless of repo priorities.

There was a bug where the repo with the highest priority would be
responsible for specifying the suggested version code. When doing so, it
would only select from the list of apks available in that repo. This
improves the calculation so that when any given repos app gets a
suggested version code assigned, it selects from _all_ available apks,
not just those from the repository in question.

Fixes #974.
This commit is contained in:
Peter Serwylo 2017-04-28 10:50:27 +10:00
parent 294e1d2821
commit 6c08e054f5

View File

@ -957,12 +957,13 @@ public class AppProvider extends FDroidProvider {
final boolean unstableUpdates = Preferences.get().getUnstableUpdates(); final boolean unstableUpdates = Preferences.get().getUnstableUpdates();
String restrictToStable = unstableUpdates ? "" : (apk + "." + ApkTable.Cols.VERSION_CODE + " <= " + app + "." + Cols.UPSTREAM_VERSION_CODE + " AND "); String restrictToStable = unstableUpdates ? "" : (apk + "." + ApkTable.Cols.VERSION_CODE + " <= " + app + "." + Cols.UPSTREAM_VERSION_CODE + " AND ");
String updateSql = String updateSql =
"UPDATE " + app + " SET " + Cols.SUGGESTED_VERSION_CODE + " = ( " + "UPDATE " + app + " SET " + Cols.SUGGESTED_VERSION_CODE + " = ( " +
" SELECT MAX( " + apk + "." + ApkTable.Cols.VERSION_CODE + " ) " + " SELECT MAX( " + apk + "." + ApkTable.Cols.VERSION_CODE + " ) " +
" FROM " + apk + " FROM " + apk +
" WHERE " + " WHERE " +
app + "." + Cols.ROW_ID + " = " + apk + "." + ApkTable.Cols.APP_ID + " AND " + joinToApksRegardlessOfRepo() + " AND " +
restrictToStable + restrictToStable +
" ( " + app + "." + Cols.IS_COMPATIBLE + " = 0 OR " + apk + "." + Cols.IS_COMPATIBLE + " = 1 ) ) " + " ( " + app + "." + Cols.IS_COMPATIBLE + " = 0 OR " + apk + "." + Cols.IS_COMPATIBLE + " = 1 ) ) " +
" WHERE " + Cols.UPSTREAM_VERSION_CODE + " > 0 "; " WHERE " + Cols.UPSTREAM_VERSION_CODE + " > 0 ";
@ -970,6 +971,29 @@ public class AppProvider extends FDroidProvider {
db().execSQL(updateSql); db().execSQL(updateSql);
} }
/**
* Ensure that when we select a list of {@link ApkTable} rows for which to calculate the
* {@link Cols#SUGGESTED_VERSION_CODE}, that we select all apks belonging to the same package,
* regardless of which repo they come from. We can't just join {@link ApkTable} onto the
* {@link AppMetadataTable}, because the {@link AppMetadataTable} table is specific to a repo.
*
* This is required so that apps always have the highest possible
* {@link Cols#SUGGESTED_VERSION_CODE}, regardless of the repository priorities. Without this,
* then each {@link AppMetadataTable} row will have a different {@link Cols#SUGGESTED_VERSION_CODE}
* depending on which repo it came from. With this, each {@link AppMetadataTable} row has the
* same {@link Cols#SUGGESTED_VERSION_CODE}, even if that version is from a different repo.
*/
private String joinToApksRegardlessOfRepo() {
final String apk = getApkTableName();
final String app = getTableName();
return app + "." + Cols.PACKAGE_ID + " = (" +
" SELECT innerAppName." + Cols.PACKAGE_ID +
" FROM " + app + " as innerAppName " +
" WHERE innerAppName." + Cols.ROW_ID + " = " + apk + "." + ApkTable.Cols.APP_ID +
") ";
}
/** /**
* We set each app's suggested version to the latest available that is * We set each app's suggested version to the latest available that is
* compatible, or the latest available if none are compatible. * compatible, or the latest available if none are compatible.
@ -989,7 +1013,7 @@ public class AppProvider extends FDroidProvider {
" SELECT MAX( " + apk + "." + ApkTable.Cols.VERSION_CODE + " ) " + " SELECT MAX( " + apk + "." + ApkTable.Cols.VERSION_CODE + " ) " +
" FROM " + apk + " FROM " + apk +
" WHERE " + " WHERE " +
app + "." + Cols.ROW_ID + " = " + apk + "." + ApkTable.Cols.APP_ID + " AND " + joinToApksRegardlessOfRepo() + " AND " +
" ( " + app + "." + Cols.IS_COMPATIBLE + " = 0 OR " + apk + "." + ApkTable.Cols.IS_COMPATIBLE + " = 1 ) ) " + " ( " + app + "." + Cols.IS_COMPATIBLE + " = 0 OR " + apk + "." + ApkTable.Cols.IS_COMPATIBLE + " = 1 ) ) " +
" WHERE COALESCE(" + Cols.UPSTREAM_VERSION_CODE + ", 0) = 0 OR " + Cols.SUGGESTED_VERSION_CODE + " IS NULL "; " WHERE COALESCE(" + Cols.UPSTREAM_VERSION_CODE + ", 0) = 0 OR " + Cols.SUGGESTED_VERSION_CODE + " IS NULL ";