Explorer

definy.warm-snapshot-cache

description
Caches at most limit of the light summaries of the newest project snapshots that are not cached yet (definy.write-snapshot-summaries, without the full snapshots). When every summary is cached, also caches the full latest snapshot of each branch (definy.read-snapshots). The Cron of a mirror calls it every run, so that the cache fills a little at a time
type
Fn(limit: Number, then: Fn(count: Number) -> @definy.service-io) -> @definy.service-io
expression
fn(limit$0, then$1) =>
  @definy.read-snapshot-events(
    offset: 0,
    acc: [],
    then: fn(events$2) =>
      #read_cached_commits<@definy.service-io>({
        version: @definy.snapshot-cache-version,
        event_hashes: @core.list-map(
          T: @definy.stored-event,
          U: String,
          f: fn(item$3) =>
            @definy.snapshot-summary-key(event_hash: $3.event_hash),
          xs: $2
        ),
        then: fn(cached$4) =>
          let missing$5 = @definy.snapshot-summaries-missing(events: $2, cached: $4);
          @definy.write-snapshot-summaries(
            event_hashes: @core.list-slice(T: String, list: $5, start: 0, end: $0),
            index: 0,
            written: [],
            then: fn(written$6) =>
              match @core.less-than(left: $0, right: @core.list-length(value: $5)) {
                true =>
                  $1(count: $0),
                false =>
                  @definy.read-snapshots(
                    then: fn(commits$7) =>
                      $1(count: @core.list-length(value: $5))
                  )
              }
          )
      })
  )
visibility
public
definy.warm-snapshot-cache (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: ANOF-KxcZUordpu8Wu2kBpeeZvAA8QCY6GRjPqPKWAA
content hash: Fp3tbIqGNEjE5X7ZZKd1dDqpHxXqDnBG2p4PlXzbgqQ