Explorer

definy.write-snapshot-summaries

description
Make the light summaries (definy.decode-stored-snapshot-summary) of the snapshots of event_hashes from index, 50 at a time, and write each 50 to the snapshot cache before the next, so that work stopped halfway (a timeout) is kept and the next request continues from there. then gets written followed by the entries made
type
Fn(
  event_hashes: List<String>,
  index: Number,
  written: List<@definy.snapshot-cache-entry>,
  then: Fn(written: List<@definy.snapshot-cache-entry>) -> @definy.service-io
) -> @definy.service-io
expression
fn(event_hashes$0, index$1, written$2, then$3) =>
  let chunk$4 = @core.list-slice(T: String, list: $0, start: $1, end: @core.plus(left: $1, right: 50));
  match @core.equal(left: @core.list-length(value: $4), right: 0) {
    true =>
      $3(written: $2),
    false =>
      @definy.store-read-events(
        event_hashes: $4,
        then: fn(events$5) =>
          let entries$6 = @core.list-fold(
              T: Union{#none, #some(@definy.stored-event)},
              A: List<@definy.snapshot-cache-entry>,
              reducer: fn(acc$7, item$8) =>
                match $8 {
                  #some(event$9) =>
                    @core.list-append(
                      list: $7,
                      item: {
                        event_hash: @definy.snapshot-summary-key(event_hash: $9.event_hash),
                        commit: @definy.decode-stored-snapshot-summary(signed_event_bytes: $9.signed_event_bytes)
                      }
                    ),
                  #none(_) =>
                    $7
                },
              init: [],
              xs: $5
            );
          #write_cached_commits<@definy.service-io>({
            version: @definy.snapshot-cache-version,
            entries: $6,
            then: fn(written$10) =>
              @definy.write-snapshot-summaries(
                event_hashes: $0,
                index: @core.plus(left: $1, right: 50),
                written: @core.list-concat(left: $2, right: $6),
                then: fn(written$11) =>
                  $3(written: $11)
              )
          })
      )
  }
visibility
public
definy.write-snapshot-summaries (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: 1mXa9kV1rRVaq3jzgrwBysMkmS7p2zl02AiFGVBi6RU
content hash: UZLhUOT3ng8oMS-Re9tdHULrpgCQfDSVAIaXkczlrDI