Explorer

definy.read-full-snapshots

description
(en) The full project snapshots of the events (with every part), from the snapshot cache or decoded from the store (and then cached). Events that are not project snapshots are left out
type
Fn(event_hashes: List<String>, then: Fn(commits: List<@definy.event-snapshot>) -> @definy.service-io) -> @definy.service-io
expression
fn(event_hashes$0, then$1) =>
  match @core.equal(left: @core.list-length(value: $0), right: 0) {
    true =>
      $1(commits: []),
    false =>
      #read_cached_commits<@definy.service-io>({
        version: @definy.snapshot-cache-version,
        event_hashes: $0,
        then: fn(cached$2) =>
          let missing$3 = @core.list-fold(
              T: String,
              A: List<String>,
              reducer: fn(acc$4, item$5) =>
                match @definy.snapshot-cache-find(entries: $2, event_hash: $5, index: 0) {
                  #some(_) =>
                    $4,
                  #none(_) =>
                    @core.list-append(list: $4, item: $5)
                },
              init: [],
              xs: $0
            );
          match @core.equal(left: @core.list-length(value: $3), right: 0) {
            true =>
              $1(commits: @definy.event-snapshots-of(entries: $2, index: 0, result: [])),
            false =>
              @definy.store-read-events(
                event_hashes: $3,
                then: fn(events$6) =>
                  let resolved$7 = @definy.snapshot-cache-resolve(
                      events: @core.list-fold(
                        T: Union{#none, #some(@definy.stored-event)},
                        A: List<@definy.stored-event>,
                        reducer: fn(acc$8, item$9) =>
                          match $9 {
                            #some(event$10) =>
                              @core.list-append(list: $8, item: $10),
                            #none(_) =>
                              $8
                          },
                        init: [],
                        xs: $6
                      ),
                      cached: [],
                      index: 0,
                      all: [],
                      fresh: []
                    );
                  #write_cached_commits<@definy.service-io>({
                    version: @definy.snapshot-cache-version,
                    entries: $7.fresh,
                    then: fn(written$11) =>
                      $1(
                        commits: @core.list-concat(
                          left: @definy.event-snapshots-of(entries: $2, index: 0, result: []),
                          right: @definy.event-snapshots-of(entries: $7.all, index: 0, result: [])
                        )
                      )
                  })
              )
          }
      })
  }
visibility
public
definy.read-full-snapshots (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: 11kowrZE8NZogTGt4iRde3PADx1B8C76c-zbLGQ1wws
content hash: Kf-A5Wc-b1HXFNAFWtjNBs9XRhOvVGSeG0dc-qLGHsE