Skip to content

Commit

Permalink
Only notify on the root URI for batch/bulk operations
Browse files Browse the repository at this point in the history
Avoid overloading ContentObservers with individual insert/update/delete Uris and instead only notify on the root content URI.

Found that this improves the cases found in #623 even more.
  • Loading branch information
ianhanniballake committed Jul 11, 2020
1 parent 59bca3e commit c0b42d9
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -862,11 +862,13 @@ abstract class MuzeiArtProvider : ContentProvider(), ProviderClient {
db.endTransaction()
// Creates a URI with the artwork ID pattern and the new row ID appended to it.
val artworkUri = ContentUris.withAppendedId(contentUri, rowId)
val documentUri = DocumentsContract.buildDocumentUri(
"$authority.documents", "$authority/$rowId")
if (applyingBatch()) {
changedUris.get()!!.add(artworkUri)
// Only notify changes on the root contentUri for batch operations
// to avoid overloading ContentObservers
changedUris.get()!!.add(contentUri)
if (hasDocumentsProvider) {
val documentUri = DocumentsContract.buildChildDocumentsUri(
"$authority.documents", authority)
changedUris.get()!!.add(documentUri)
}
} else {
Expand All @@ -875,6 +877,8 @@ abstract class MuzeiArtProvider : ContentProvider(), ProviderClient {
}
context.contentResolver.notifyChange(artworkUri, null)
if (hasDocumentsProvider) {
val documentUri = DocumentsContract.buildDocumentUri(
"$authority.documents", "$authority/$rowId")
context.contentResolver.notifyChange(documentUri, null)
}
}
Expand Down Expand Up @@ -921,7 +925,9 @@ abstract class MuzeiArtProvider : ContentProvider(), ProviderClient {
val documentUri = DocumentsContract.buildChildDocumentsUri(
"$authority.documents", authority)
if (applyingBatch()) {
changedUris.get()!!.add(uri)
// Only notify changes on the root contentUri for batch operations
// to avoid overloading ContentObservers
changedUris.get()!!.add(contentUri)
if (hasDocumentsProvider) {
changedUris.get()!!.add(documentUri)
}
Expand Down Expand Up @@ -972,7 +978,9 @@ abstract class MuzeiArtProvider : ContentProvider(), ProviderClient {
val documentUri = DocumentsContract.buildChildDocumentsUri(
"$authority.documents", authority)
if (applyingBatch()) {
changedUris.get()!!.add(uri)
// Only notify changes on the root contentUri for batch operations
// to avoid overloading ContentObservers
changedUris.get()!!.add(contentUri)
if (hasDocumentsProvider) {
changedUris.get()!!.add(documentUri)
}
Expand Down

0 comments on commit c0b42d9

Please sign in to comment.