Create ID lookup cache for manifest (#75)

This commit is contained in:
Huang Xin
2025-06-10 12:09:54 +00:00
committed by GitHub
parent f2d32152df
commit d7affcf969
+2 -1
View File
@@ -645,6 +645,7 @@ class Resources {
item.properties = item.properties?.split(/\s/) item.properties = item.properties?.split(/\s/)
return item return item
}) })
this.manifestById = new Map(this.manifest.map(item => [item.id, item]))
this.spine = $$itemref this.spine = $$itemref
.map(getAttributes('idref', 'id', 'linear', 'properties')) .map(getAttributes('idref', 'id', 'linear', 'properties'))
.map(item => (item.properties = item.properties?.split(/\s/), item)) .map(item => (item.properties = item.properties?.split(/\s/), item))
@@ -675,7 +676,7 @@ class Resources {
this.cfis = CFI.fromElements($$itemref) this.cfis = CFI.fromElements($$itemref)
} }
getItemByID(id) { getItemByID(id) {
return this.manifest.find(item => item.id === id) return this.manifestById.get(id)
} }
getItemByHref(href) { getItemByHref(href) {
return this.manifest.find(item => item.href === href) return this.manifest.find(item => item.href === href)