refactor: remove cache to speedup building
This commit is contained in:
@@ -4,7 +4,6 @@ import shutil
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
from joblib import Memory
|
|
||||||
from mistletoe import Document
|
from mistletoe import Document
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
@@ -18,18 +17,10 @@ class Build:
|
|||||||
def __init__(self, config: Config):
|
def __init__(self, config: Config):
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
memory = Memory("./cache", verbose=0)
|
|
||||||
self.env = Environment(loader=FileSystemLoader("templates/"))
|
self.env = Environment(loader=FileSystemLoader("templates/"))
|
||||||
self.env.filters["shuffle_answers"] = self.__filter_shuffle_answers
|
self.env.filters["shuffle_answers"] = self.__filter_shuffle_answers
|
||||||
self.questions = self.__parse_katalog()
|
self.questions = self.__parse_katalog()
|
||||||
|
|
||||||
# Decorate the method with memory.cache
|
|
||||||
self.__build_question = memory.cache(self.__build_question)
|
|
||||||
self.__build_question_slide = memory.cache(self.__build_question_slide)
|
|
||||||
self.__build_chapter = memory.cache(self.__build_chapter)
|
|
||||||
self.__build_section = memory.cache(self.__build_section)
|
|
||||||
self.__build_chapter_slidedeck = memory.cache(self.__build_chapter_slidedeck)
|
|
||||||
|
|
||||||
def __parse_katalog(self):
|
def __parse_katalog(self):
|
||||||
with self.config.p_data_fragenkatalog.open() as file:
|
with self.config.p_data_fragenkatalog.open() as file:
|
||||||
fragenkatalog = json.load(file)
|
fragenkatalog = json.load(file)
|
||||||
@@ -48,7 +39,6 @@ class Build:
|
|||||||
|
|
||||||
return questions
|
return questions
|
||||||
|
|
||||||
# cached
|
|
||||||
def __build_question(self, number, template_file="html/question.html"):
|
def __build_question(self, number, template_file="html/question.html"):
|
||||||
"""Combines the original question dataset from BNetzA with our internal metadata"""
|
"""Combines the original question dataset from BNetzA with our internal metadata"""
|
||||||
|
|
||||||
@@ -127,7 +117,6 @@ class Build:
|
|||||||
def __build_question_slide(self, input):
|
def __build_question_slide(self, input):
|
||||||
return self.__build_question(input, template_file="slide/question.html")
|
return self.__build_question(input, template_file="slide/question.html")
|
||||||
|
|
||||||
# cached
|
|
||||||
def __build_page(self, content, course_wrapper=False, sidebar=None):
|
def __build_page(self, content, course_wrapper=False, sidebar=None):
|
||||||
page_template = self.env.get_template("html/page.html")
|
page_template = self.env.get_template("html/page.html")
|
||||||
return page_template.render(content=content, course_wrapper=course_wrapper, sidebar=sidebar)
|
return page_template.render(content=content, course_wrapper=course_wrapper, sidebar=sidebar)
|
||||||
@@ -156,7 +145,6 @@ class Build:
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
tqdm.write(f"\033[31mPhoto #{id} not found\033[0m")
|
tqdm.write(f"\033[31mPhoto #{id} not found\033[0m")
|
||||||
|
|
||||||
# cached
|
|
||||||
def __build_chapter(self, edition, edition_name, number, chapter, next_chapter=None):
|
def __build_chapter(self, edition, edition_name, number, chapter, next_chapter=None):
|
||||||
chapter_template = self.env.get_template("html/chapter.html")
|
chapter_template = self.env.get_template("html/chapter.html")
|
||||||
next_chapter_template = self.env.get_template("html/next_chapter.html")
|
next_chapter_template = self.env.get_template("html/next_chapter.html")
|
||||||
@@ -181,7 +169,6 @@ class Build:
|
|||||||
with (self.config.p_data_html / f"{include}.html").open() as file:
|
with (self.config.p_data_html / f"{include}.html").open() as file:
|
||||||
return file.read()
|
return file.read()
|
||||||
|
|
||||||
# cached
|
|
||||||
def __build_section(
|
def __build_section(
|
||||||
self,
|
self,
|
||||||
edition,
|
edition,
|
||||||
|
|||||||
Reference in New Issue
Block a user