Explorar o código

Use lazy_static to ensure we compile templates once

Santiago Pastorino %!s(int64=4) %!d(string=hai) anos
pai
achega
bc39982e75
Modificáronse 2 ficheiros con 15 adicións e 6 borrados
  1. 3 0
      src/lib.rs
  2. 12 6
      src/meeting.rs

+ 3 - 0
src/lib.rs

@@ -1,5 +1,8 @@
 #![allow(clippy::new_without_default)]
 #![allow(clippy::new_without_default)]
 
 
+#[macro_use]
+extern crate lazy_static;
+
 use anyhow::Context;
 use anyhow::Context;
 use handlers::HandlerError;
 use handlers::HandlerError;
 use interactions::ErrorComment;
 use interactions::ErrorComment;

+ 12 - 6
src/meeting.rs

@@ -40,17 +40,21 @@ pub struct IssueDecorator {
     pub assignees: String,
     pub assignees: String,
 }
 }
 
 
-#[async_trait]
-impl<'a> Action for Step<'a> {
-    async fn call(&self) -> String {
-        let tera = match Tera::new("templates/*") {
+lazy_static! {
+    pub static ref TEMPLATES: Tera = {
+        match Tera::new("templates/*") {
             Ok(t) => t,
             Ok(t) => t,
             Err(e) => {
             Err(e) => {
                 println!("Parsing error(s): {}", e);
                 println!("Parsing error(s): {}", e);
                 ::std::process::exit(1);
                 ::std::process::exit(1);
             }
             }
-        };
+        }
+    };
+}
 
 
+#[async_trait]
+impl<'a> Action for Step<'a> {
+    async fn call(&self) -> String {
         let gh = GithubClient::new(
         let gh = GithubClient::new(
             Client::new(),
             Client::new(),
             env::var("GITHUB_API_TOKEN").expect("Missing GITHUB_API_TOKEN"),
             env::var("GITHUB_API_TOKEN").expect("Missing GITHUB_API_TOKEN"),
@@ -135,6 +139,8 @@ impl<'a> Action for Step<'a> {
             }
             }
         }
         }
 
 
-        tera.render(&format!("{}.tt", self.name), &context).unwrap()
+        TEMPLATES
+            .render(&format!("{}.tt", self.name), &context)
+            .unwrap()
     }
     }
 }
 }