Skip to content

Commit

Permalink
I don't know how to config PouchDB auto_compaction, so here this is
Browse files Browse the repository at this point in the history
  • Loading branch information
retrodaredevil committed Apr 20, 2023
1 parent 73ac491 commit 7fe81f2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
ioLibVersion = '2.3.0' // https://github.com/retrodaredevil/io-lib/releases
okhttpVersion = "4.10.0" // https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
// couchdbJavaVersion = '1.1.0'
couchdbJavaVersion = "cf377882a0a85ce1ff37b5bcc23a5389d900d66f".substring(0, 10)
couchdbJavaVersion = "74927f44c30104c1d961039893dda2ec6ed13a80".substring(0, 10)
dockerComposePluginVersion = "0.16.12" // https://github.com/avast/gradle-docker-compose-plugin/releases
errorpronePluginVersion = '3.0.1' // https://github.com/tbroyer/gradle-errorprone-plugin/releases
errorproneCoreVersion = '2.18.0' // https://mvnrepository.com/artifact/com.google.errorprone/error_prone_core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ private void setupReplicator(CouchDbInstance inMemoryInstance, CouchProperties i
// Note that although we have isReplicatorKnownToBeFullySetup, we don't return in the above loop because we need to constantly duplicate packets from last X hours
isReplicatorKnownToBeFullySetup = true;
}
private void compactDatabase(CouchDbInstance inMemoryInstance) throws CouchDbException {
for (SolarThingDatabaseType databaseType : new SolarThingDatabaseType[]{
SolarThingDatabaseType.STATUS,
SolarThingDatabaseType.EVENT,
// no open
SolarThingDatabaseType.CLOSED,
// no alter
SolarThingDatabaseType.CACHE,
}) {
CouchDbDatabase database = inMemoryInstance.getDatabase(databaseType.getName());
database.compact();
}
LOGGER.debug("Compacted all databases");
}

@Scheduled(fixedDelayString = "PT20S", initialDelayString = "PT2S")
@Async
Expand All @@ -222,5 +236,14 @@ public void setupInMemoryReplicator() throws CouchDbException {
setupReplicator(inMemoryInstance, inMemoryCouch, externalInstance, externalCouch);
}
}
@Scheduled(fixedDelayString = "PT5M", initialDelayString = "PT1M")
@Async
public void compactInMemoryDatabases() throws CouchDbException {
if (replicateCouchDbDatabaseSettings != null) {
CouchProperties inMemoryCouch = couchDbDatabaseSettings.getCouchProperties();
CouchDbInstance inMemoryInstance = CouchDbUtil.createInstance(inMemoryCouch, couchDbDatabaseSettings.getOkHttpProperties());
compactDatabase(inMemoryInstance);
}
}

}

0 comments on commit 7fe81f2

Please sign in to comment.