Repos added later should take higher priority.

The database still treats repos with a _low_ number as _low_ priority.
This means it sounds weird when you say "Repo with priority 1 is the
least important", but other than that, everything works as expected now.

Technically we could recreate the query to update the repo metadata
within DBHelper, but that is difficult because it is sort of build into
the content providers. Unfortunately, we are unable to access content
providers from the DBHelper.

In the future if we are able to migrate away from content providers to a
more dumb data access layer, then we could reuse the query to update the
metadata priorities in the DBHelper. However that is a tomorrow problem.
This commit is contained in:
Peter Serwylo 2017-04-04 16:26:42 +10:00
parent 89e103fc23
commit c6efdbb20c
2 changed files with 12 additions and 2 deletions

View File

@ -960,7 +960,7 @@ public class AppProvider extends FDroidProvider {
final String app = getTableName();
final String highestPriority =
"SELECT MIN(r." + RepoTable.Cols.PRIORITY + ") " +
"SELECT MAX(r." + RepoTable.Cols.PRIORITY + ") " +
"FROM " + RepoTable.NAME + " AS r " +
"JOIN " + getTableName() + " AS m ON (m." + Cols.REPO_ID + " = r." + RepoTable.Cols._ID + ") " +
"WHERE m." + Cols.PACKAGE_ID + " = " + "metadata." + Cols.PACKAGE_ID;

View File

@ -190,7 +190,7 @@ class DBHelper extends SQLiteOpenHelper {
+ InstalledAppTable.Cols.HASH + " TEXT NOT NULL"
+ " );";
protected static final int DB_VERSION = 67;
protected static final int DB_VERSION = 68;
private final Context context;
@ -272,6 +272,16 @@ class DBHelper extends SQLiteOpenHelper {
addCategoryTables(db, oldVersion);
addIndexV1Fields(db, oldVersion);
addIndexV1AppFields(db, oldVersion);
recalculatePreferredMetadata(db, oldVersion);
}
private void recalculatePreferredMetadata(SQLiteDatabase db, int oldVersion) {
if (oldVersion >= 68) {
return;
}
Log.i(TAG, "Previously, the repository metadata was being interpreted backwards. Need to force a repo refresh to fix this.");
resetTransient(db);
}
private void addIndexV1AppFields(SQLiteDatabase db, int oldVersion) {