Pass through the ID of the repo being updated to the temp tables.
This will allow for more intelligent and efficient copying of data back and forth from temp to persistent tables.
This commit is contained in:
parent
571e05398f
commit
8c3441939f
@ -139,7 +139,7 @@ public class IndexV1Updater extends RepoUpdater {
|
||||
* and {@link Apk} instances. This uses {@link RepoPersister} to add the apps
|
||||
* and packages to the database in {@link RepoPersister#saveToDb(App, List)}
|
||||
* to write the {@link Repo}, and commit the whole thing in
|
||||
* {@link RepoPersister#commit(ContentValues)}. One confusing thing about this
|
||||
* {@link RepoPersister#commit(ContentValues, long)}. One confusing thing about this
|
||||
* whole process is that {@link RepoPersister} needs to first create and entry
|
||||
* in the database, then fetch the ID from the database to populate
|
||||
* {@link Repo#id}. That has to happen first, then the rest of the {@code Repo}
|
||||
@ -265,7 +265,7 @@ public class IndexV1Updater extends RepoUpdater {
|
||||
if (repo.mirrors != null && repo.mirrors.length > 0) {
|
||||
contentValues.put(Schema.RepoTable.Cols.MIRRORS, Utils.serializeCommaSeparatedString(repo.mirrors));
|
||||
}
|
||||
repoPersister.commit(contentValues);
|
||||
repoPersister.commit(contentValues, repo.getId());
|
||||
profiler.log("Persited to database.");
|
||||
|
||||
|
||||
|
@ -280,7 +280,7 @@ public class RepoUpdater {
|
||||
private void commitToDb() throws UpdateException {
|
||||
Log.i(TAG, "Repo signature verified, saving app metadata to database.");
|
||||
notifyCommittingToDb();
|
||||
persister.commit(repoDetailsToSave);
|
||||
persister.commit(repoDetailsToSave, repo.getId());
|
||||
}
|
||||
|
||||
private void assertSigningCertFromXmlCorrect() throws SigningException {
|
||||
|
@ -66,9 +66,9 @@ public class RepoPersister {
|
||||
}
|
||||
}
|
||||
|
||||
public void commit(ContentValues repoDetailsToSave) throws RepoUpdater.UpdateException {
|
||||
public void commit(ContentValues repoDetailsToSave, long repoIdToCommit) throws RepoUpdater.UpdateException {
|
||||
flushBufferToDb();
|
||||
TempAppProvider.Helper.commitAppsAndApks(context);
|
||||
TempAppProvider.Helper.commitAppsAndApks(context, repoIdToCommit);
|
||||
RepoProvider.Helper.update(context, repo, repoDetailsToSave);
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ public class RepoPersister {
|
||||
// the index was signed with until we've finished reading it - and we don't
|
||||
// want to put stuff in the real database until we are sure it is from a
|
||||
// trusted source. It also helps performance as it is done via an in-memory database.
|
||||
TempAppProvider.Helper.init(context);
|
||||
TempAppProvider.Helper.init(context, repo.getId());
|
||||
hasBeenInitialized = true;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ public class TempApkProvider extends ApkProvider {
|
||||
private static final UriMatcher MATCHER = new UriMatcher(-1);
|
||||
|
||||
static {
|
||||
MATCHER.addURI(getAuthority(), PATH_INIT, CODE_INIT);
|
||||
MATCHER.addURI(getAuthority(), PATH_INIT + "/#", CODE_INIT);
|
||||
MATCHER.addURI(getAuthority(), PATH_APK_FROM_ANY_REPO + "/#/*", CODE_APK_FROM_ANY_REPO);
|
||||
MATCHER.addURI(getAuthority(), PATH_APK_FROM_REPO + "/#/#", CODE_APK_FROM_REPO);
|
||||
MATCHER.addURI(getAuthority(), PATH_REPO_APK + "/#/*", CODE_REPO_APK);
|
||||
@ -76,12 +76,15 @@ public class TempApkProvider extends ApkProvider {
|
||||
* table and populates it with all the data from the real apk provider table.
|
||||
*
|
||||
* This is package local because it must be invoked after
|
||||
* {@link org.fdroid.fdroid.data.TempAppProvider.Helper#init(Context)}. Due to this
|
||||
* {@link org.fdroid.fdroid.data.TempAppProvider.Helper#init(Context, long)}. Due to this
|
||||
* dependence, that method invokes this one itself, rather than leaving it to the
|
||||
* {@link RepoPersister}.
|
||||
*/
|
||||
static void init(Context context) {
|
||||
Uri uri = Uri.withAppendedPath(getContentUri(), PATH_INIT);
|
||||
static void init(Context context, long repoIdToUpdate) {
|
||||
Uri uri = getContentUri().buildUpon()
|
||||
.appendPath(PATH_INIT)
|
||||
.appendPath(Long.toString(repoIdToUpdate))
|
||||
.build();
|
||||
context.getContentResolver().insert(uri, new ContentValues());
|
||||
}
|
||||
}
|
||||
@ -89,7 +92,7 @@ public class TempApkProvider extends ApkProvider {
|
||||
@Override
|
||||
public Uri insert(Uri uri, ContentValues values) {
|
||||
if (MATCHER.match(uri) == CODE_INIT) {
|
||||
initTable();
|
||||
initTable(Long.parseLong(uri.getLastPathSegment()));
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -124,7 +127,7 @@ public class TempApkProvider extends ApkProvider {
|
||||
|
||||
}
|
||||
|
||||
private void initTable() {
|
||||
private void initTable(long repoIdBeingUpdated) {
|
||||
final SQLiteDatabase db = db();
|
||||
final String memoryDbName = TempAppProvider.DB;
|
||||
db.execSQL(DBHelper.CREATE_TABLE_APK.replaceFirst(Schema.ApkTable.NAME, memoryDbName + "." + getTableName()));
|
||||
|
@ -43,8 +43,8 @@ public class TempAppProvider extends AppProvider {
|
||||
private static final UriMatcher MATCHER = new UriMatcher(-1);
|
||||
|
||||
static {
|
||||
MATCHER.addURI(getAuthority(), PATH_INIT, CODE_INIT);
|
||||
MATCHER.addURI(getAuthority(), PATH_COMMIT, CODE_COMMIT);
|
||||
MATCHER.addURI(getAuthority(), PATH_INIT + "/#", CODE_INIT);
|
||||
MATCHER.addURI(getAuthority(), PATH_COMMIT + "/#", CODE_COMMIT);
|
||||
MATCHER.addURI(getAuthority(), PATH_APPS + "/#/*", APPS);
|
||||
MATCHER.addURI(getAuthority(), PATH_SPECIFIC_APP + "/#/*", CODE_SINGLE);
|
||||
}
|
||||
@ -105,10 +105,13 @@ public class TempAppProvider extends AppProvider {
|
||||
* Deletes the old temporary table (if it exists). Then creates a new temporary apk provider
|
||||
* table and populates it with all the data from the real apk provider table.
|
||||
*/
|
||||
public static void init(Context context) {
|
||||
Uri uri = Uri.withAppendedPath(getContentUri(), PATH_INIT);
|
||||
public static void init(Context context, long repoIdToUpdate) {
|
||||
Uri uri = getContentUri().buildUpon()
|
||||
.appendPath(PATH_INIT)
|
||||
.appendPath(Long.toString(repoIdToUpdate))
|
||||
.build();
|
||||
context.getContentResolver().insert(uri, new ContentValues());
|
||||
TempApkProvider.Helper.init(context);
|
||||
TempApkProvider.Helper.init(context, repoIdToUpdate);
|
||||
}
|
||||
|
||||
public static List<App> findByPackageNames(Context context,
|
||||
@ -122,8 +125,11 @@ public class TempAppProvider extends AppProvider {
|
||||
* Saves data from the temp table to the apk table, by removing _EVERYTHING_ from the real
|
||||
* apk table and inserting all of the records from here. The temporary table is then removed.
|
||||
*/
|
||||
public static void commitAppsAndApks(Context context) {
|
||||
Uri uri = Uri.withAppendedPath(getContentUri(), PATH_COMMIT);
|
||||
public static void commitAppsAndApks(Context context, long repoIdToCommit) {
|
||||
Uri uri = getContentUri().buildUpon()
|
||||
.appendPath(PATH_COMMIT)
|
||||
.appendPath(Long.toString(repoIdToCommit))
|
||||
.build();
|
||||
context.getContentResolver().insert(uri, new ContentValues());
|
||||
}
|
||||
}
|
||||
@ -137,11 +143,11 @@ public class TempAppProvider extends AppProvider {
|
||||
public Uri insert(Uri uri, ContentValues values) {
|
||||
switch (MATCHER.match(uri)) {
|
||||
case CODE_INIT:
|
||||
initTable();
|
||||
initTable(Long.parseLong(uri.getLastPathSegment()));
|
||||
return null;
|
||||
case CODE_COMMIT:
|
||||
updateAllAppDetails();
|
||||
commitTable();
|
||||
commitTable(Long.parseLong(uri.getLastPathSegment()));
|
||||
return null;
|
||||
default:
|
||||
return super.insert(uri, values);
|
||||
@ -220,7 +226,7 @@ public class TempAppProvider extends AppProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private void initTable() {
|
||||
private void initTable(long repoIdBeingUpdated) {
|
||||
final SQLiteDatabase db = db();
|
||||
ensureTempTableDetached(db);
|
||||
db.execSQL("ATTACH DATABASE ':memory:' AS " + DB);
|
||||
@ -242,7 +248,7 @@ public class TempAppProvider extends AppProvider {
|
||||
return "INSERT INTO " + toTable + " (" + cols + ") SELECT " + cols + " FROM " + fromTable;
|
||||
}
|
||||
|
||||
private void commitTable() {
|
||||
private void commitTable(long repoIdToCommit) {
|
||||
final SQLiteDatabase db = db();
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
@ -110,7 +110,7 @@ public class ProviderUriTests {
|
||||
|
||||
// Required so that the `assertValidUri` calls below will indeed have a real temp_fdroid_app
|
||||
// table to query.
|
||||
TempAppProvider.Helper.init(TestUtils.createContextWithContentResolver(resolver));
|
||||
TempAppProvider.Helper.init(TestUtils.createContextWithContentResolver(resolver), 123);
|
||||
|
||||
List<String> packageNames = new ArrayList<>(2);
|
||||
packageNames.add("org.fdroid.fdroid");
|
||||
|
Loading…
x
Reference in New Issue
Block a user