Generate SSD remote truth import loop from typed Jerboa
ober
8dbc439b113ccc65a52a2d054376e83eef36066d
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -9105,6 +9105,7 @@ remoteTruthPayloadCount remoteTruthPayloadTruths remoteTruthEntriesCount remoteTruthEntryAt remoteTruthEntryTruth remoteTruthEntryModified + countImportedRemoteTruthEntries remoteDumpImportedCount) (type JSONArray) (type JSONObject) @@ -9154,6 +9155,20 @@ (json-object-opt-int-default entry "modified" (int 0))) (def (remoteDumpImportedCount (payload : JSONObject)) : Int32 (json-object-opt-int32-default payload "imported" (int32 0))) + (def (countImportedRemoteTruthEntries + (entries : JSONArray) + (importTruth : (-> JSONObject Int Bool))) : Int32 + (for/fold ((imported (int32 0))) + ((i (in-range (int32 0) (remoteTruthEntriesCount entries)))) + (let ((entry (remoteTruthEntryAt entries i))) + (let ((entryTruth (remoteTruthEntryTruth entry))) + (if (remoteTruthPayloadHasTruth entryTruth) + (let ((truth (remoteTruthPayloadTruthOrEmpty entryTruth)) + (modified (remoteTruthEntryModified entry))) + (if (invoke importTruth truth modified) + (+ imported (int32 1)) + imported)) + imported))))) (def (bestRemoteTruthForSession (session : SsdSession) (entries : JSONArray)) : (Nullable JSONObject) (for/fold ((best (nullable-none JSONObject))) @@ -11980,14 +11995,8 @@ " }" " val entries = remoteTruthPayloadTruths(payload)" " if (zipEntryCountExceeded(remoteTruthEntriesCount(entries), MAX_ZIP_ENTRIES)) throw IllegalStateException(\"Too many remote truth entries\")" - " var imported = 0" - " for (i in 0 until remoteTruthEntriesCount(entries)) {" - " val entry = remoteTruthEntryAt(entries, i)" - " val entryTruth = remoteTruthEntryTruth(entry)" - " if (!remoteTruthPayloadHasTruth(entryTruth)) continue" - " val truth = remoteTruthPayloadTruthOrEmpty(entryTruth)" - " val modified = remoteTruthEntryModified(entry)" - " if (writeRemoteTruth(truth, modified)) imported += 1" + " var imported = countImportedRemoteTruthEntries(entries) { truth, modified ->" + " writeRemoteTruth(truth, modified)" " }" " val bestForSession = bestRemoteTruthForSession(session, entries)" " if (remoteTruthPayloadHasTruth(bestForSession)) {"