more efficient persisting

This commit is contained in:
Zlatin Balevsky
2018-07-23 19:41:59 +01:00
parent 5a2019f8eb
commit 19a688037f
3 changed files with 23 additions and 15 deletions

View File

@@ -103,10 +103,12 @@ class PersisterService extends Service {
private void persistFiles() {
location.delete()
def sharedFiles = fileSource.getSharedFiles()
sharedFiles.each { k, v ->
def json = toJson(k,v)
json = JsonOutput.toJson(json)
location.append "$json\n"
location.withPrintWriter { writer ->
sharedFiles.each { k, v ->
def json = toJson(k,v)
json = JsonOutput.toJson(json)
writer.println json
}
}
}

View File

@@ -107,13 +107,15 @@ class HostCache extends Service {
private void save() {
storage.delete()
hosts.each { dest, host ->
if (allowHost(host)) {
def map = [:]
map.destination = dest.toBase64()
map.failures = host.failures
def json = JsonOutput.toJson(map)
storage.append("${json}\n")
storage.withPrintWriter { writer ->
hosts.each { dest, host ->
if (allowHost(host)) {
def map = [:]
map.destination = dest.toBase64()
map.failures = host.failures
def json = JsonOutput.toJson(map)
writer.println json
}
}
}
}

View File

@@ -49,12 +49,16 @@ class TrustService extends Service {
private void persist() {
persistGood.delete()
good.each {
persistGood.append("${it.toBase64()}\n")
persistGood.withPrintWriter { writer ->
good.each {
writer.println it.toBase64()
}
}
persistBad.delete()
bad.each {
persistBad.append("${it.toBase64()}\n")
persistBad.withPrintWriter { writer ->
bad.each {
writer.println it.toBase64()
}
}
}