diff options
author | Vincent Ambo <tazjin@gmail.com> | 2018-04-14T14·33+0200 |
---|---|---|
committer | Vincent Ambo <tazjin@gmail.com> | 2018-04-14T14·33+0200 |
commit | 8c30ef92f652f411679408344031706745346f02 (patch) | |
tree | f15ab0ebead519c105c03c128ae7f04c4194074b /src/render.rs | |
parent | a90d1cc1a41e405ea397b06a3bc1907291c98b65 (diff) |
refactor(db): Store thread body in the posts table
This is a simplification over the previous approach. The OP of a thread is just a normal post like any other in this model, which allows some code simplifications (and future query convenience).
Diffstat (limited to 'src/render.rs')
-rw-r--r-- | src/render.rs | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/src/render.rs b/src/render.rs index 37f1c4b7fe60..f47830fa847e 100644 --- a/src/render.rs +++ b/src/render.rs @@ -101,24 +101,15 @@ fn md5_hex(input: &[u8]) -> String { } fn prepare_thread(comrak: &ComrakOptions, page: ThreadPage) -> RenderableThreadPage { - let mut posts = vec![RenderablePost { - // Always pin the ID of the first post. - id: 0, - body: markdown_to_html(&page.thread.body, comrak), - posted: page.thread.posted.into(), - author_name: page.thread.author_name, - author_gravatar: md5_hex(page.thread.author_email.as_bytes()), - }]; - - for post in page.posts { - posts.push(RenderablePost { + let posts = page.posts.into_iter().map(|post| { + RenderablePost { id: post.id, body: markdown_to_html(&post.body, comrak), posted: post.posted.into(), author_name: post.author_name, author_gravatar: md5_hex(post.author_email.as_bytes()), - }); - } + } + }).collect(); RenderableThreadPage { posts, |