aboutsummaryrefslogtreecommitdiff
path: root/internal/readings/readings.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-08-25 10:45:28 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-08-25 10:45:28 +0200
commitf110c338718a6eea3693fb6afb4f7fcc5b77003b (patch)
tree52b6adb382445a0762f63fb862361d7fbd8637f2 /internal/readings/readings.go
parentfd3eda0da228d2417b8b7f9007533e214d7a5e80 (diff)
parentb24702cc9b8d7f2e408bb92032e8f7fa2aaa836b (diff)
downloadlectio-f110c338718a6eea3693fb6afb4f7fcc5b77003b.tar.gz
lectio-f110c338718a6eea3693fb6afb4f7fcc5b77003b.zip
merge: make the calendar engine stop repeating whole-year work per day
A seven-day view resolved the year seven times. Each readings.Load stacked the calendar data layers and re-read the Bible book table -- both date-independent -- and the EF path rebuilt the year's entire transfer plan and its occupancy scan on every single day. Three logic-neutral fixes: hoist the date-independent setup out of the Days loop; memoise the EF transfer plan on (year, Selection, content hash of the merged sanctoral); and build the occupancy index once alongside it rather than scanning per candidate. EF's seven-day view goes 74ms to 16ms, its multiple over OF from ~13x to ~3x. OF is unchanged, as it never touched the EF paths. Output is byte-identical throughout, proven by SHA-256 over a 492-case sweep spanning both forms, both languages, four corpora, the Triduum, a Requiem day and the three Joseph/Annunciation collision years. The caches are keyed on content, not identity, so a user overlay invalidates them -- asserted by a test that varies the overlay and requires the answer to change, itself mutation-proved by dropping the content hash and watching it fail.
Diffstat (limited to 'internal/readings/readings.go')
-rw-r--r--internal/readings/readings.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/internal/readings/readings.go b/internal/readings/readings.go
index d0d7bf9..29eff5a 100644
--- a/internal/readings/readings.go
+++ b/internal/readings/readings.go
@@ -25,8 +25,22 @@ type Options struct {
// liturgical colour -- see liturgy.DayInfo) for the configured form
// (cfg.Lectionary: "traditional" or "new") and applies part filtering. Every
// reading is resolved offline from the embedded calendar and lectionary data.
+//
+// Load is LoadWith(Prepare(cfg), cfg, opts) -- a single call's worth of
+// convenience. A caller resolving several dates against the same cfg (a
+// week/month view) should call Prepare once and use LoadWith directly instead
+// of paying Prepare's cost on every date; see Prepared's doc comment
+// (internal/readings/offline.go).
func Load(cfg config.Config, opts Options) ([]liturgy.Section, liturgy.DayInfo, error) {
- secs, info, err := offlineLoad(cfg, opts.Date)
+ return LoadWith(Prepare(cfg), cfg, opts)
+}
+
+// LoadWith is Load, given an already-built Prepared (see Prepare) instead of
+// building its own. Reuse one Prepared across every date resolved against the
+// same cfg to skip re-stacking the calendar layers and re-parsing the book
+// table per date -- the fast path mobile.Days's multi-day loop uses.
+func LoadWith(p Prepared, cfg config.Config, opts Options) ([]liturgy.Section, liturgy.DayInfo, error) {
+ secs, info, err := offlineLoadWith(p, cfg, opts.Date)
if err != nil {
return nil, liturgy.DayInfo{}, err
}