From 78db19000dd5a306b01cea4de1c3327b53ff2db4 Mon Sep 17 00:00:00 2001 From: vallentin Date: Tue, 19 Apr 2022 20:28:15 +0200 Subject: Skip caching calls (Resolves #667) --- askama_derive/src/generator.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'askama_derive/src/generator.rs') diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 5921609..e8d15f6 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -1196,11 +1196,12 @@ impl<'a> Generator<'a> { expr_buf.buf, self.input.escaper ), }; + let is_cacheable = !matches!(s, Expr::Call(..)); use std::collections::hash_map::Entry; let id = match expr_cache.entry(expression.clone()) { - Entry::Occupied(e) => *e.get(), - Entry::Vacant(e) => { + Entry::Occupied(e) if is_cacheable => *e.get(), + e => { let id = self.named; self.named += 1; @@ -1209,7 +1210,10 @@ impl<'a> Generator<'a> { buf_expr.write(&expression); buf_expr.writeln(",")?; - e.insert(id); + if let Entry::Vacant(e) = e { + e.insert(id); + } + id } }; -- cgit