From 5af754d68572a0e76307936373ed07f9ea57d9b9 Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Fri, 23 Aug 2019 19:06:58 +0200 Subject: [PATCH] add cache --- src/etherpad2latex.nim | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/etherpad2latex.nim b/src/etherpad2latex.nim index 1eec0af..52454ff 100644 --- a/src/etherpad2latex.nim +++ b/src/etherpad2latex.nim @@ -28,13 +28,16 @@ when isMainModule: texFile = workingDir / pad & ".tex" pdfFile = workingDir / pad & ".pdf" - writeFile(texFile, content) - - let (output, exitCode) = execCmdEx(quoteShellCommand(["pdflatex", "-halt-on-error", texFile])) - if exitCode == 0: - resp(Http200, readFile(pdfFile), contentType = "application/pdf") + if fileExists(texFile) and readFile(texFile) == content and fileExists(pdfFile): + # Use file from cache + resp(Http200, readFile(pdfFile), contentType="application/pdf") else: - resp output + writeFile(texFile, content) + let (output, exitCode) = execCmdEx(quoteShellCommand(["pdflatex", "-halt-on-error", texFile])) + if exitCode == 0: + resp(Http200, readFile(pdfFile), contentType="application/pdf") + else: + resp output let s = newSettings(port=Port(opts.port.parseInt)) var j = initJester(main, settings=s)