## What is the database? LiveSync does not synchronise files directly. All files are synchronised to the local database. At this time, files are separated into two or more entries; the metadata and chunks. And they will be synchronised between each device by replicating their own local databases to the remote database. ```mermaid graph TB subgraph local[device_A] storage[Storage] <--> localDB[Database]; end subgraph anotherLocal[device_B] anotherStorage[Storage] <--> anotherLocalDB[Database]; end localDB <--> remoteDB[CouchDB]; anotherLocalDB <--> remoteDB; ``` Chunks are key to low-traffic replication and synchronisation. Usually, editable text-file will be split by new-line-mark. Chunks are keyed by their contents, and all metadata has a list of chunk keys as below. ```mermaid graph LR A.md-->A; B.md-->B; C.md-->C;     A-->1["Willy Wonka, Willy Wonka"];     A-->2["The amazing Chocolatier"];     A-->1;     A-->3["Everybody give a cheer!"];     B-->4["Charlie and the Chocolate Factory"];     B-->5[" is a 2005 musical fantasy film"];     C-->6["When I heard `Wonka's welcome song`, so upset."];     C-->7["I'm still afraid this."];     subgraph storage A.md B.md C.md end subgraph localDatabase subgraph metadata A B C end subgraph chunks 1 2 3 4 5 6 7 end end ``` Figure 1 A: ``` Willy Wonka, Willy Wonka The amazing Chocolatier Willy Wonka, Willy Wonka Everybody give a cheer! ``` B: ``` Charlie and the Chocolate Factory is a 2005 musucal fantasy film ``` C: ``` When I heard `Wonka's welcome song`, so upset. I'm still afraid this. ``` After we edit the files, the metadata is usually updated and a few new chunks are born. And if there already exists one made from the same contents, it will be shared. C: ``` When I heard `Wonka's welcome song`, so upset. I'm still afraid the song that starts with this... Willy Wonka, Willy Wonka ``` ```mermaid graph LR A.md-->A; B.md-->B; C.md-->C;     A-->1["Willy Wonka, Willy Wonka"];     A-->2["The amazing Chocolatier"];     A-->1;     A-->3["Everybody give a cheer!"];     B-->4["Charlie and the Chocolate Factory"];     B-->5[" is a 2005 musical fantasy film"];     C-->6["When I heard `Wonka's welcome song`, so upset."];     7["I'm still afraid "];     C-->8["I'm still afraid the song that starts with this..."];     C-->1;     subgraph storage A.md B.md C.md end subgraph localDatabase subgraph metadata A B C end subgraph chunks 1 2 3 4 5 6 7 8 end end ``` Figure 2 (metadata `C` and chunk `When I heard...` will be transfered) Therefore, we can transfer only the metadata and some limited chunks and keep a low bandwidth and less traffic. That enables *LiveSync*. As shown in Figure 2, there will still be old chunks that are not currently referenced. Therefore, although these chunks may one day be re-used, the database will continue to bloat. Owning to this, At some point, we must rebuild the database. However, it is up to us to decide when to do so. It can be performed by `Rebuild` button on the `Remote database` pane. ## End-to-end encryption When we enabled the end-to-end encryption, only the chunks are encrypted, only at the remote database. This process will be performed while synchronising automatically and transparently. However, we have to rebuild the database when we changed the passphrase. Otherwise, there are many chunks which have been encrypted by the old passphrase.