From 1b4306c3a39047db8374890f962846559757a8c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20St=C4=99pie=C5=84?= Date: Thu, 17 Sep 2015 17:13:45 +0200 Subject: [PATCH] create-preview: simplify the more marker lookup This commit replaces a regular expression lookup with a simple String/indexOf substring search. It addresses pathological cases in which re-find took several seconds to process contents of a blog post. An example of such a case was a post with 16kB of nested HTML tags in a single line. --- src/cryogen_core/compiler.clj | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index 5349d32..5d78bba 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -246,11 +246,17 @@ {:active-page "tags" :uri (str blog-prefix "/tags.html")})))) +(defn content-until-more-marker + [^String content] + (let [index (.indexOf content "")] + (if (pos? index) + (subs content 0 index)))) + (defn create-preview "Creates a single post preview" [blocks-per-preview post] (merge (select-keys post [:title :author :date :uri]) - {:content (or (re-find #".+?(?=)" (:content post)) + {:content (or (content-until-more-marker (:content post)) (->> ((tagsoup/parse-string (:content post)) 2) (drop 2) (take blocks-per-preview)