Compare commits
No commits in common. "3b7a7db0caf2a64d135bed827171135856a9a7d0" and "e45fed69bb87f980c13ecb81f9b72d332fe66b94" have entirely different histories.
3b7a7db0ca
...
e45fed69bb
@ -24,7 +24,7 @@ local ThreadCreateError = {
|
|||||||
app:get("all_topics", "", function(self)
|
app:get("all_topics", "", function(self)
|
||||||
self.topic_list = db.query([[
|
self.topic_list = db.query([[
|
||||||
SELECT
|
SELECT
|
||||||
topics.id, topics.name, topics.slug, topics.description, topics.is_locked,
|
topics.name, topics.slug, topics.description, topics.is_locked,
|
||||||
users.username AS latest_thread_username,
|
users.username AS latest_thread_username,
|
||||||
threads.title AS latest_thread_title,
|
threads.title AS latest_thread_title,
|
||||||
threads.slug AS latest_thread_slug,
|
threads.slug AS latest_thread_slug,
|
||||||
@ -43,44 +43,6 @@ app:get("all_topics", "", function(self)
|
|||||||
ORDER BY
|
ORDER BY
|
||||||
topics.sort_order ASC
|
topics.sort_order ASC
|
||||||
]])
|
]])
|
||||||
|
|
||||||
local active_threads_raw = db.query([[
|
|
||||||
WITH ranked_threads AS (
|
|
||||||
SELECT
|
|
||||||
threads.topic_id, threads.id AS thread_id, threads.title AS thread_title, threads.slug AS thread_slug,
|
|
||||||
posts.id AS post_id, posts.created_at AS post_created_at,
|
|
||||||
users.username,
|
|
||||||
ROW_NUMBER() OVER (PARTITION BY threads.topic_id ORDER BY posts.created_at DESC) AS rn
|
|
||||||
FROM
|
|
||||||
threads
|
|
||||||
JOIN
|
|
||||||
posts ON threads.id = posts.thread_id
|
|
||||||
LEFT JOIN
|
|
||||||
users ON posts.user_id = users.id
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
topic_id,
|
|
||||||
thread_id, thread_title, thread_slug,
|
|
||||||
post_id, post_created_at,
|
|
||||||
username
|
|
||||||
FROM
|
|
||||||
ranked_threads
|
|
||||||
WHERE
|
|
||||||
rn = 1
|
|
||||||
ORDER BY
|
|
||||||
topic_id
|
|
||||||
]])
|
|
||||||
self.active_threads = {}
|
|
||||||
for _, thread in ipairs(active_threads_raw) do
|
|
||||||
self.active_threads[tonumber(thread.topic_id)] = {
|
|
||||||
thread_title = thread.thread_title,
|
|
||||||
thread_slug = thread.thread_slug,
|
|
||||||
post_id = thread.post_id,
|
|
||||||
username = thread.username,
|
|
||||||
post_created_at = thread.post_created_at,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
self.me = util.get_logged_in_user_or_transient(self)
|
self.me = util.get_logged_in_user_or_transient(self)
|
||||||
return {render = "topics.topics"}
|
return {render = "topics.topics"}
|
||||||
end)
|
end)
|
||||||
|
@ -23,12 +23,6 @@
|
|||||||
<span>
|
<span>
|
||||||
Latest thread: <a href="<%= url_for("thread", {slug = topic.latest_thread_slug}) %>"><%= topic.latest_thread_title %></a> by <a href="<%= url_for("user", {username = topic.latest_thread_username}) %>"><%= topic.latest_thread_username %></a> on <% render("views.common.timestamp", {timestamp = topic.latest_thread_created_at}) -%>
|
Latest thread: <a href="<%= url_for("thread", {slug = topic.latest_thread_slug}) %>"><%= topic.latest_thread_title %></a> by <a href="<%= url_for("user", {username = topic.latest_thread_username}) %>"><%= topic.latest_thread_username %></a> on <% render("views.common.timestamp", {timestamp = topic.latest_thread_created_at}) -%>
|
||||||
</span>
|
</span>
|
||||||
<% if active_threads[topic.id] then %>
|
|
||||||
<% local thread = active_threads[topic.id] %>
|
|
||||||
<span>
|
|
||||||
Latest post in: <a href="<%= url_for("thread", {slug = thread.thread_slug}) %>"><%= thread.thread_title %></a> by <a href="<%= url_for("user", {username = thread.username}) %>"><%= thread.username %></a> at <a href="<%= get_post_url(thread.post_id) %>"><% render("views.common.timestamp", {timestamp = thread.post_created_at}) -%></a>
|
|
||||||
</span>
|
|
||||||
<% end %>
|
|
||||||
<% else %>
|
<% else %>
|
||||||
<i>No threads yet.</i>
|
<i>No threads yet.</i>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<%
|
<%
|
||||||
local unread_posts_text = " (" .. thread.unread_count .. " unread post" .. (thread.unread_count > 1 and "s" or "")-- .. ")"
|
local unread_posts_text = " (" .. thread.unread_count .. " unread post" .. (thread.unread_count > 1 and "s" or "")-- .. ")"
|
||||||
%>
|
%>
|
||||||
<a class="accordion-title" href="<%= url_for("thread", {slug = thread.thread_slug}, {after = latest_post_id}) .. "#post-" .. latest_post_id %>" title="Jump to latest post"><%= thread.thread_title .. unread_posts_text %>, latest at <% render("views.common.timestamp", {timestamp = thread.newest_post_time}) -%>)</a>
|
<a class="accordion-title" href="<%= url_for("thread", {slug = thread.thread_slug}, {after = latest_post_id}) .. "#post-" .. latest_post_id %>" title="Jump to latest post"><%= thread.thread_title .. unread_posts_text %>, latest at <span class="timestamp" data-utc=<%= thread.newest_post_time %>><%= os.date("%c", thread.newest_post_time) %></span>)</a>
|
||||||
<form action="<%= url_for("thread_subscribe", {slug = thread.thread_slug}) %>" method="post">
|
<form action="<%= url_for("thread_subscribe", {slug = thread.thread_slug}) %>" method="post">
|
||||||
<input type="hidden" name="subscribe" value="read">
|
<input type="hidden" name="subscribe" value="read">
|
||||||
<input type="submit" value="Mark Thread as Read">
|
<input type="submit" value="Mark Thread as Read">
|
||||||
|
Loading…
Reference in New Issue
Block a user