add periodic compaction

master
Brian Hicks 2020-05-24 06:01:38 -05:00
parent ec3399ca33
commit 12b1838df4
3 changed files with 24 additions and 2 deletions

View File

@ -122,6 +122,7 @@ type Msg
| PouchDBPutSuccessfully Value
| TimerTriggeredSave
| TimerTriggeredSyncAll
| TimerTriggeredCompaction
| FocusedOnEditor
| UserClickedNewNote
| UserEditedNode String
@ -157,6 +158,7 @@ type Effect
| Put Value
| FocusOnEditor
| SyncOnce Sync
| Compact
type UpdatedRevision
@ -240,6 +242,9 @@ update msg model =
, Batch (List.map SyncOnce model.settings.syncs)
)
TimerTriggeredCompaction ->
( model, Compact )
FocusedOnEditor ->
( model, NoEffect )
@ -632,6 +637,9 @@ perform model effect =
Nothing ->
Cmd.none
Compact ->
compact ()
port put : Value -> Cmd msg
@ -639,6 +647,9 @@ port put : Value -> Cmd msg
port syncOnce : String -> Cmd msg
port compact : () -> Cmd msg
port putSuccessfully : (Value -> msg) -> Sub msg
@ -647,7 +658,8 @@ subscriptions model =
Sub.batch
[ putSuccessfully PouchDBPutSuccessfully
, Time.every 1000 (\_ -> TimerTriggeredSave)
, Time.every 10000 (\_ -> TimerTriggeredSyncAll)
, Time.every 60000 (\_ -> TimerTriggeredSyncAll)
, Time.every 120000 (\_ -> TimerTriggeredCompaction)
-- Using a 1-second resolution is more than enough for most UI
-- concerns. If it needs to be more precise, crank this down! But

View File

@ -62,6 +62,13 @@ var db = new PouchDB("notes");
.catch((err) => console.error(err));
});
// compacting
app.ports.compact.subscribe(() => {
db.compact()
.then(() => console.log("compaction success"))
.catch(err) => console.error(err));
})
// syncing
app.ports.syncOnce.subscribe((url) => {
db.replicate.from(url).on("complete", (info) => {

View File

@ -65,7 +65,10 @@ testPerform effect =
FocusOnEditor ->
SCmd.none
StartSyncing _ ->
SyncOnce _ ->
SCmd.none
Compact ->
SCmd.none