Skip to content

Commit

Permalink
clean up page
Browse files Browse the repository at this point in the history
  • Loading branch information
lindseymoore committed Jun 3, 2024
1 parent b119e68 commit f9508d4
Showing 1 changed file with 0 additions and 362 deletions.
362 changes: 0 additions & 362 deletions source/sdk/files/reduce-file-size.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,163 +113,6 @@ Reduce File Size on Launch of Realm

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

.. tabs-drivers::

tabs:
- id: cpp-sdk
content: |

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.

.. literalinclude:: /examples/generated/cpp/compact.snippet.compact-database.cpp
:language: cpp

- id: csharp
content: |

You can configure Realm to check the realm file each time
it is opened by specifying a
:dotnet-sdk:`ShouldCompactDelegate <reference/Realms.RealmConfiguration.ShouldCompactDelegate.html>`
in the configuration. The following code example shows how to do this:

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

If the delegate returns ``true`` -- and the file is not in use -- the realm file
is compacted prior to making the instance available.

- id: dart
content: |

You can define a :flutter-sdk:`shouldCompactCallback()
<realm/LocalConfiguration/shouldCompactCallback.html>` as a property of a
realm's configuration. You can use this with both local-only and synced realms
with the :flutter-sdk:`Configuration.local() <realm/Configuration/local.html>`
and :flutter-sdk:`Configuration.flexibleSync() <realm/Configuration/flexibleSync.html>`
methods, respectively.

This callback takes two ``int`` values representing the total number of
bytes and the used bytes of the realm file on disk. The callback returns
a ``bool``. Compaction only occurs if the ``bool`` returns ``true`` and
another process is not currently accessing the realm file.

The most basic usage is to define a file size at which compaction should occur.

.. literalinclude:: /examples/generated/flutter/compact_realm_test.snippet.compact-with-callback.dart
:language: dart

You can define more complex logic if you need to optimize performance for
different use cases. For example, you could set a threshold for compaction
when a certain percentage of the file size is used.

.. literalinclude:: /examples/generated/flutter/compact_realm_test.snippet.compact-with-callback-and-logic.dart
:language: dart

- id: java
content: |

Specify the :java-sdk:`compactOnLaunch()
<io/realm/RealmConfiguration.Builder.html#compactOnLaunch-io.realm.CompactOnLaunchCallback->`
builder option when opening the first connection to a realm in your
Android application.

.. important:: Compact All Production Applications

Every production application should implement compacting to
periodically reduce realm file size.

- id: javascript
content: |

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:

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

- id: kotlin
content: |


You can configure Realm to compact the realm file each time it is opened
by setting a callback for the `compactOnLaunch
<{+kotlin-local-prefix+}io.realm.kotlin/-configuration/-shared-builder/compact-on-launch.html>`__ function
for the configuration. When you call ``compactOnLaunch`` for the
configuration, the `DEFAULT_COMPACT_ON_LAUNCH_CALLBACK
<{+kotlin-local-prefix+}io.realm.kotlin/-realm/-companion/
-d-e-f-a-u-l-t_-c-o-m-p-a-c-t_-o-n_-l-a-u-n-c-h_-c-a-l-l-b-a-c-k.html>`__
will trigger if the file is above 50 MB and 50% or more of the space in
the realm file is unused. You can specify custom compaction settings
when calling ``compactOnLaunch`` depending on your applications needs.
The following code example shows how to do this:

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

- id: objectivec
content: |

Use :objc-sdk:`shouldCompactOnLaunch <Classes/RLMRealmConfiguration.html>`
on a realm's configuration object to compact a realm.
Specify conditions to execute this method, such as:

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

For more information about the conditions to execute in the method, see:
:ref:`ios-when-to-compact-a-realm`.

.. important:: Compacting may not occur

Compacting cannot occur while a realm is being accessed,
regardless of any configuration settings.

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

- id: swift
content: |

Use :swift-sdk:`shouldCompactOnLaunch()<Structs/Realm/Configuration.html>`
(Swift) on a realm's configuration object to compact a realm.
Specify conditions to execute this method, such as:

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

For more information about the conditions to execute in the method, see:
:ref:`ios-when-to-compact-a-realm`.

.. important:: Compacting may not occur

Compacting cannot occur while a realm is being accessed,
regardless of any configuration settings.

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

When you use the Swift async/await syntax to open a realm asynchronously, you can also
compact a realm in the background.

.. literalinclude:: /examples/generated/code/start/Compacting.snippet.async-compact.swift
:language: swift

.. include:: /includes/swift-async-await-support.rst

- id: typescript
content: |

Missing example

Compact() Method
~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -322,114 +165,6 @@ Compact() Method

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

.. tabs-drivers::

tabs:
- id: cpp-sdk
content: |

No example

- id: csharp
content: |

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:

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

The ``Compact`` method will return true if the operation is successful.

- id: dart
content: |

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.

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

- id: java
content: |

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.

???? code example

- id: javascript
content: |

You can compact a realm file whenever you'd like by calling
the :js-sdk:`compact() <Realm.html#compact>` method:

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

The ``compact()`` method will return true if the operation is successful.

- id: kotlin
content: |

You can compact a realm file without having to open it by calling
the `compactRealm <{+kotlin-local-prefix+}
io.realm.kotlin/-realm/-companion/compact-realm.html>`__ method:

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

The ``compactRealm`` method will return true if the operation is successful
and false if not.

.. important::

`compactRealm <{+kotlin-local-prefix+}io.realm.kotlin/-realm/-companion/compact-realm.html>`__
is not available on Windows (JVM), and will throw a
`NotImplementedError <https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-not-implemented-error/>`_ there.

- id: objectivec
content: |

No example

- id: swift
content: |

No example

- id: typescript
content: |

Alternatively, you can compact a realm file without first obtaining an instance
of the realm by calling the :realm-react-sdk:`compact() <classes/Realm-1.html#compact>`
method:

.. literalinclude:: /examples/generated/react-native/js/compact-realm.test.snippet.compactRN.js
:language: javascript

The ``compact()`` method will return true if the operation is successful.

Make a Compacted Copy
~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -485,103 +220,6 @@ Make a Compacted Copy

.. include:: /includes/sdk-examples/manage-files/reduce-file-size-compacted-copy.rst

.. tabs-drivers::

tabs:
- id: cpp-sdk
content: |

No example

- id: csharp
content: |

No example


- id: dart
content: |

No example

- id: java
content: |

No example

- id: javascript
content: |

You can save a compacted (and optionally :ref:`encrypted
<node-encrypt-a-realm>`) copy of a realm to another file location
with the :js-sdk:`Realm.writeCopyTo()
<Realm.html#writeCopyTo>`
method. The destination file cannot already exist.

.. important::

Avoid calling ``writeCopyTo()`` within a :ref:`write transaction
<node-write-transactions>`. If called within a write transaction, this
method copies the absolute latest data. This includes any
**uncommitted** changes you made in the transaction before this
method call.

- id: kotlin
content: |

You can save a compacted (and optionally :ref:`encrypted
<kotlin-encrypt-a-realm>`) copy of a realm to another file location
with the `Realm.writeCopyTo
<{+kotlin-local-prefix+}io.realm.kotlin/-realm/write-copy-to.html>`__
method. The destination file cannot already exist.

.. important::

Avoid calling ``writeCopyTo`` within a :ref:`write transaction
<kotlin-write-transactions>`. If called within a write transaction, this
method copies the absolute latest data. This includes any
**uncommitted** changes you made in the transaction before this
method call.

- id: objectivec
content: |

No example

- id: swift
content: |

You can save a compacted (and optionally :ref:`encrypted
<ios-encrypt-a-realm>`) copy of a realm to another file location
with the :swift-sdk:`Realm.writeCopy(toFile:encryptionKey:)
<Structs/Realm.html#/s:10RealmSwift0A0V9writeCopy6toFile13encryptionKeyy10Foundation3URLV_AG4DataVSgtKF>`
method. The destination file cannot already exist.

.. important::

Avoid calling this method within a :ref:`write transaction
<ios-write-transactions>`. If called within a write transaction, this
method copies the absolute latest data. This includes any
**uncommitted** changes you made in the transaction before this
method call.

- id: typescript
content: |

You can save a compacted (and optionally :ref:`encrypted <react-native-encrypt-a-realm>`)
copy of a realm to another file location with the
:realm-react-sdk:`Realm.writeCopyTo() <classes/Realm-1.html#writeCopyTo>`
method. The destination file cannot already exist.

.. important::

Avoid calling ``writeCopyTo()`` within a :ref:`write transaction <react-native-write-transactions>`.
If called within a write transaction, this
method copies the absolute latest data. This includes any
**uncommitted** changes you made in the transaction before this
method call.

.. Once again in JS, rather than TS, so should I just say no example for TS? Should this just go to a RN specific page?

Tips for Manually Compacting a Realm
------------------------------------
Expand Down

0 comments on commit f9508d4

Please sign in to comment.