ocaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Replace the transclusion cache with a mainmatter cache

The problem with the transclusion cache is that frontmatter needs to
render differently depending on the location of the transclusion (e.g.
to deal with designated parents in expanded titles).

+19 -13
+19 -13
lib/frontend/Legacy_xml_client.ml
··· 66 66 67 67 module Loop_detection = Loop_detection_effect.Make () 68 68 69 - (* It's fine to have a global transclusion cache since URIs fully qualify a tree*) 70 - let transclusion_cache = Hashtbl.create 1000 69 + let mainmatter_cache = Hashtbl.create 1000 71 70 72 71 let render_xml_qname qname = 73 72 let qname = Xmlns.normalise_qname qname in ··· 91 90 X.optional_ X.toc dict.included_in_toc; 92 91 X.optional_ X.numbered dict.numbered 93 92 ] 93 + 94 94 let rec render_section forest (section : T.content T.section) : P.node = 95 95 let@ _ = Xmlns.run in 96 96 X.tree ··· 103 103 [X.info [] [P.txt "Transclusion loop detected, rendering stopped."]] 104 104 else 105 105 let@ () = Loop_detection.add_seen_uri_opt section.frontmatter.uri in 106 - render_content forest section.mainmatter 106 + render_mainmatter forest section 107 107 ] 108 108 109 + and render_mainmatter forest (section : T.content T.section) = 110 + match section.frontmatter.uri with 111 + | None -> render_content forest section.mainmatter 112 + | Some uri -> 113 + match Hashtbl.find_opt mainmatter_cache uri with 114 + | None -> 115 + let nodes = render_content forest section.mainmatter in 116 + Hashtbl.add mainmatter_cache uri nodes; 117 + nodes 118 + | Some nodes -> nodes 119 + 109 120 and render_frontmatter (forest : State.t) (frontmatter : T.content T.frontmatter) : P.node = 110 121 let result = 111 122 X.frontmatter ··· 238 249 X.resource_source [X.type_ "%s" source.type_; X.resource_part "%s" source.part] "<![CDATA[%s]]>" source.source 239 250 240 251 and render_transclusion (forest : State.t) (transclusion : T.transclusion) : P.node list = 241 - match Hashtbl.find_opt transclusion_cache transclusion with 242 - | Some nodes -> nodes 252 + match State.get_content_of_transclusion transclusion forest with 243 253 | None -> 244 - match State.get_content_of_transclusion transclusion forest with 245 - | None -> 246 - Reporter.fatal (Resource_not_found transclusion.href) 247 - | Some content -> 248 - let nodes = render_content forest content in 249 - Hashtbl.add transclusion_cache transclusion nodes; 250 - nodes 254 + Reporter.fatal (Resource_not_found transclusion.href) 255 + | Some content -> 256 + render_content forest content 251 257 252 258 and render_link (forest : State.t) (link : T.content T.link) : P.node list = 253 259 let article_opt = State.get_article link.href forest in ··· 350 356 X.mainmatter [] @@ 351 357 begin 352 358 let@ () = Loop_detection.add_seen_uri_opt article.frontmatter.uri in 353 - render_content forest article.mainmatter 359 + render_mainmatter forest @@ T.article_to_section article 354 360 end; 355 361 X.backmatter [] @@ 356 362 let@ () = In_backmatter.run ~env: true in