a fresh start :)
This commit is contained in:
@@ -30,23 +30,6 @@ class Users(Model):
|
||||
def is_default_avatar(self):
|
||||
return self.avatar_id == 1
|
||||
|
||||
def get_latest_posts(self):
|
||||
q = """SELECT
|
||||
posts.id, posts.created_at, post_history.content, post_history.edited_at, threads.title AS thread_title, topics.name as topic_name, threads.slug as thread_slug
|
||||
FROM
|
||||
posts
|
||||
JOIN
|
||||
post_history ON posts.current_revision_id = post_history.id
|
||||
JOIN
|
||||
threads ON posts.thread_id = threads.id
|
||||
JOIN
|
||||
topics ON threads.topic_id = topics.id
|
||||
WHERE
|
||||
posts.user_id = ?
|
||||
ORDER BY posts.created_at DESC
|
||||
LIMIT 10"""
|
||||
return db.query(q, self.id)
|
||||
|
||||
def get_post_stats(self):
|
||||
q = """SELECT
|
||||
COUNT(DISTINCT posts.id) AS post_count,
|
||||
@@ -148,47 +131,6 @@ class Topics(Model):
|
||||
topics.sort_order ASC"""
|
||||
return db.query(q)
|
||||
|
||||
@classmethod
|
||||
def get_active_threads(cls):
|
||||
q = """
|
||||
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, users.display_name,
|
||||
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, display_name
|
||||
FROM
|
||||
ranked_threads
|
||||
WHERE
|
||||
rn = 1
|
||||
ORDER BY
|
||||
topic_id"""
|
||||
|
||||
active_threads_raw = db.query(q)
|
||||
active_threads = {}
|
||||
for thread in active_threads_raw:
|
||||
active_threads[int(thread['topic_id'])] = {
|
||||
'thread_title': thread['thread_title'],
|
||||
'thread_slug': thread['thread_slug'],
|
||||
'post_id': thread['post_id'],
|
||||
'username': thread['username'],
|
||||
'display_name': thread['display_name'],
|
||||
'post_created_at': thread['post_created_at']
|
||||
}
|
||||
return active_threads
|
||||
|
||||
def get_threads(self, per_page, page, sort_by = "activity"):
|
||||
order_clause = ""
|
||||
if sort_by == "thread":
|
||||
|
||||
Reference in New Issue
Block a user