Platform Manual
CRUD Operations

Evicting and Removing



Considerations



Access Frequency and Relevance Considerations

In peer-to-peer system design, there are technical tradeoffs between the amount of data synced across peers and the timeliness of access to synced data:

  • The greater the amount of data synced across connected peer devices, the more timely offline read access becomes. That is, database resilience in offline scenarios increases when there are more documents being synced across distributed peers.
  • The fewer the number of documents replicated, the less the likelihood that peer devices run out of disk space and experience memory leaks, and the performance of the peer-to-peer mesh network that interconnects them degrades.

For considerations on using the Evict and Subscribe methods, see Timing Subscriptions and Evictions.

For advanced concepts related to design tradeoffs in distributed system architecture, see Cloud-Optional Design.

Evict Method


Swift
Kotlin
JS
Java
C#
C++
Rust


Using Evict for Local and Live Queries


Swift
Kotlin
JS
Java
C#
C++
Rust


For more information, see Finding and Observing.

Using Evict for Replication Queries



Timing Subscriptions and Evictions



In addition, take a balanced approach when using the Subscribe and Evict methods; as in, consider the advantages and drawbacks of each method and use them as appropriate for the specific needs and requirements of your app.

Key considerations for using Subscription and Eviction methods include:

  • Use Subscribe to sync more data across connected peers in the mesh, but be mindful of potential increased network usage that may degrade performance.
  • Use Evict to remove data stored locally in an effort to manage local storage capacity and improve performance.

Forcing Evictions



Swift
Kotlin
JS
Java
C#
C++
Rust


Remove Method



Invoking the remove method results in irreversible data loss.

Once a document is removed, it is permanently eliminated throughout the Ditto system and can never be restored; however, as of Ditto version 4.0 release, if a document was previously removed, you can reverse the removal. For more information, see Reversing Removal Operations.

Removing Documents


Swift
Kotlin
JS
Java
C#
C++
Rust


Swift
Kotlin
JS
Java
C#
C++
Rust


Soft-Delete Flag



Adding a Soft-Delete Flag

To add a soft-delete pattern, set the isArchived field value to true:

JSON


Querying Non-Archived Documents

To query to monitor documents that are NOT archived, establish a live query using the Find method enclosed with !isArchived, and then construct your live query callback.

For example, the following code demonstrates looking for documents that are not archived. Once found, the documents output, or log, to your console.

JS


Removing Soft-Delete Flag

To remove the flag and reactivate the document, set the isArchived field to false:

JS