Migrate some classifier calls off of legacy DB driver.

This commit is contained in:
dosiecki 2015-01-14 10:57:37 -08:00
parent 1136d9ec56
commit 3f63e00f28
3 changed files with 12 additions and 20 deletions

View file

@ -661,6 +661,15 @@ public class BlurDatabaseHelper {
}
}
public void clearClassifiersForFeed(String feedId) {
String[] selArgs = new String[] {feedId};
synchronized (RW_MUTEX) {dbRW.delete(DatabaseConstants.CLASSIFIER_TABLE, DatabaseConstants.CLASSIFIER_ID + " = ?", selArgs);}
}
public void insertClassifier(Classifier classifier) {
bulkInsertValues(DatabaseConstants.CLASSIFIER_TABLE, classifier.getContentValues());
}
public static void closeQuietly(Cursor c) {
if (c == null) return;
try {c.close();} catch (Exception e) {;}

View file

@ -53,9 +53,6 @@ public class FeedProvider extends ContentProvider {
synchronized (BlurDatabaseHelper.RW_MUTEX) {
final SQLiteDatabase db = databaseHelper.getWritableDatabase();
switch (uriMatcher.match(uri)) {
case CLASSIFIERS_FOR_FEED:
return db.delete(DatabaseConstants.CLASSIFIER_TABLE, DatabaseConstants.CLASSIFIER_ID + " = ?", new String[] { uri.getLastPathSegment() });
default:
return 0;
}
@ -78,12 +75,6 @@ public class FeedProvider extends ContentProvider {
db.insertWithOnConflict(DatabaseConstants.USER_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
resultUri = uri.buildUpon().appendPath(values.getAsString(DatabaseConstants.USER_USERID)).build();
break;
// Inserting a classifier for a feed
case CLASSIFIERS_FOR_FEED:
values.put(DatabaseConstants.CLASSIFIER_ID, uri.getLastPathSegment());
db.insertWithOnConflict(DatabaseConstants.CLASSIFIER_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
break;
// Inserting a comment
case STORY_COMMENTS:

View file

@ -188,17 +188,9 @@ public class FeedUtils {
// next, update the local DB
classifier.getMapForType(classifierType).put(key, classifierAction);
Uri classifierUri = FeedProvider.CLASSIFIER_URI.buildUpon().appendPath(feedId).build();
try {
// TODO: for feeds with many classifiers, this could be much faster by targeting just the row that changed
context.getContentResolver().delete(classifierUri, null, null);
for (ContentValues classifierValues : classifier.getContentValues()) {
context.getContentResolver().insert(classifierUri, classifierValues);
}
} catch (Exception e) {
Log.w(FeedUtils.class.getName(), "Could not update classifier in local storage.", e);
}
classifier.feedId = feedId;
dbHelper.clearClassifiersForFeed(feedId);
dbHelper.insertClassifier(classifier);
}
public static void shareStory(Story story, Context context) {