summaryrefslogtreecommitdiffstats
path: root/packages/SettingsProvider
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@android.com>2010-03-09 17:58:53 -0800
committerBrad Fitzpatrick <bradfitz@android.com>2010-03-09 17:58:53 -0800
commit547a96bc12f25f585271c678395d4c991f08c52d (patch)
tree59c3521a9cc6e2fba7204a45d800425b1c705b3d /packages/SettingsProvider
parentf3bcc62584f714ac4994601d74761b6f14e1fc48 (diff)
downloadframeworks_base-547a96bc12f25f585271c678395d4c991f08c52d.zip
frameworks_base-547a96bc12f25f585271c678395d4c991f08c52d.tar.gz
frameworks_base-547a96bc12f25f585271c678395d4c991f08c52d.tar.bz2
SettingsProvider: dup-suppress from cache.
On insert(), check to see if the value is redundant by checking if it's the same value already in our cache (but without faulting it in to check). If so, avoid hitting sqlite or spamming all the notification listeners with such uselessness. This reportedly is happening a fair bit. Change-Id: If58feb3ff1d00027dd927e0900087388cbcd72ae
Diffstat (limited to 'packages/SettingsProvider')
-rw-r--r--packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java23
1 files changed, 22 insertions, 1 deletions
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
index 83937fa..1b4ba81 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
@@ -436,11 +436,16 @@ public class SettingsProvider extends ContentProvider {
if (!parseProviderList(url, initialValues)) return null;
}
+ SettingsCache cache = SettingsCache.forTable(args.table);
+ String value = initialValues.getAsString(Settings.NameValueTable.VALUE);
+ if (SettingsCache.isRedundantSetValue(cache, name, value)) {
+ return Uri.withAppendedPath(url, name);
+ }
+
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
final long rowId = db.insert(args.table, null, initialValues);
if (rowId <= 0) return null;
- SettingsCache cache = SettingsCache.forTable(args.table);
SettingsCache.populate(cache, initialValues); // before we notify
if (LOCAL_LOGV) Log.v(TAG, args.table + " <- " + initialValues);
@@ -669,5 +674,21 @@ public class SettingsProvider extends ContentProvider {
}
}
+ /**
+ * For suppressing duplicate/redundant settings inserts early,
+ * checking our cache first (but without faulting it in),
+ * before going to sqlite with the mutation.
+ */
+ public static boolean isRedundantSetValue(SettingsCache cache, String name, String value) {
+ if (cache == null) return false;
+ synchronized (cache) {
+ Bundle bundle = cache.get(name);
+ if (bundle == null) return false;
+ String oldValue = bundle.getPairValue();
+ if (oldValue == null && value == null) return true;
+ if ((oldValue == null) != (value == null)) return false;
+ return oldValue.equals(value);
+ }
+ }
}
}