Skip to content

Commit

Permalink
compact method section 1/2
Browse files Browse the repository at this point in the history
  • Loading branch information
lindseymoore committed Jun 3, 2024
1 parent 544fc5a commit 1260018
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 15 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Alternatively, you can compact a realm file without first obtaining an instance
to the realm by calling the
:dotnet-sdk:`Compact() <reference/Realms.Realm.html#Realms_Realm_Compact_Realms_RealmConfigurationBase_>`
method. The following example shows how to do this:


The ``Compact`` method will return true if the operation is successful.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
You can compact a realm file by calling :flutter-sdk:`Realm.compact()
<realm/Realm/compact.html>`. This method takes a :flutter-sdk:`Configuration
<topics/Configuration-topic.html>` as an argument. When you use this method,
the device must have enough free space to make a copy of the realm.

``Realm.compact()`` obtains an instance of the realm, and opens it to
trigger any schema version upgrades, file format upgrades, migration and
initial data callbacks. Upon successfully opening the realm and performing
these operations, this method then compacts the realm.

If successful, a call to ``Realm.compact()`` returns ``true``.

Do not call this method from inside a transaction. You also cannot compact an
open realm.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
You can remove unused space by **compacting** the realm file by manually
calling :java-sdk:`compactRealm()
<io/realm/Realm.html#compactRealm-io.realm.RealmConfiguration->`

.. important:: Compact All Production Applications

Every production application should implement compacting to
periodically reduce realm file size.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
You can compact a realm file whenever you'd like by calling
the :js-sdk:`compact() <Realm.html#compact>` method:

The ``compact()`` method will return true if the operation is successful.
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
Use the :cpp-sdk:`should_compact_on_launch() <structrealm_1_1internal_1_1bridge_1_1realm_1_1config.html>`
method on the database configuration to attempt to compact the database.
Specify conditions to execute this method, such as:

- The size of the file on disk
- How much free space the file contains

The following example shows setting the conditions to compact a realm if the
file is above 100 MB and 50% or less of the space in the realm file is used.
You can configure Realm to check the realm file each time it is opened
by specifying a :js-sdk:`shouldCompact <Realm.html#~Configuration>` function
for the configuration. The following code example shows how to do this:
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.. tabs-drivers::

tabs:
- id: cpp-sdk
content: |

.. literalinclude:: /examples/MissingPlaceholders/api.cpp
:language: cpp

- id: csharp
content: |

.. literalinclude:: /examples/generated/dotnet/Compact.snippet.manual-compact.cs
:language: csharp

- id: dart
content: |

.. literalinclude:: /examples/generated/flutter/compact_realm_test.snippet.compact-static-method.dart
:language: dart

- id: java
content: |

.. literalinclude:: /examples/MissingPlaceholders/example.java
:language: java

- id: javascript
content: |

.. literalinclude:: /examples/generated/node/compacting.snippet.compactNode.js
:language: javascript

- id: kotlin
content: |

.. literalinclude:: /examples/generated/kotlin/Compacting.snippet.compactOnLaunch.kt
:language: kotlin

- id: objectivec
content: |

.. literalinclude:: /examples/generated/code/start/Compacting.snippet.compacting.m
:language: objectivec

- id: swift
content: |

.. literalinclude:: /examples/generated/code/start/Compacting.snippet.async-compact.swift
:language: swift
3 changes: 3 additions & 0 deletions source/sdk/crud/threading.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ Threading
:backlinks: none
:depth: 2
:class: singlecol


https://www.mongodb.com/docs/atlas/device-sdks/sdk/swift/realm-files/compacting/#threading
55 changes: 49 additions & 6 deletions source/sdk/files/reduce-file-size.txt
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,55 @@ Reduce File Size on Launch of Realm
Compact() Method
~~~~~~~~~~~~~~~~

.. tabs-drivers::

.. tab::
:tabid: cpp-sdk

The C++ SDK does not currently support this API.

.. tab::
:tabid: csharp

.. include:: /includes/api-details/csharp/manage-files/reduce-file-size-compact-method.rst

.. tab::
:tabid: dart

.. include:: /includes/api-details/dart/manage-files/reduce-file-size-compact-method.rst

.. tab::
:tabid: java

.. include:: /includes/api-details/java/manage-files/reduce-file-size-compact-method.rst

.. tab::
:tabid: javascript

.. include:: /includes/api-details/javascript/manage-files/reduce-file-size-compact-method.rst

.. tab::
:tabid: kotlin

.. include:: /includes/api-details/kotlin/manage-files/reduce-file-size-.rst

.. tab::
:tabid: objectivec

.. include:: /includes/api-details/objectivec/manage-files/reduce-file-size-on-launch-description.rst

.. tab::
:tabid: swift

.. include:: /includes/api-details/swift/manage-files/reduce-file-size-on-launch-description.rst

.. tab::
:tabid: typescript

.. include:: /includes/api-details/typescript/manage-files/reduce-file-size-on-launch-description.rst

.. include:: /includes/sdk-examples/manage-files/reduce-file-size-on-launch.rst

.. tabs-drivers::

tabs:
Expand Down Expand Up @@ -329,12 +378,6 @@ Compact() Method

???? code example


- id: java-kotlin
content: |

No example

- id: javascript
content: |

Expand Down

0 comments on commit 1260018

Please sign in to comment.