start user page port
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
from .db import Model
|
||||
from .db import Model, db
|
||||
from .constants import PermissionLevel
|
||||
|
||||
class Users(Model):
|
||||
@ -19,6 +19,40 @@ 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(posts.id) AS post_count,
|
||||
COUNT(DISTINCT threads.id) AS thread_count,
|
||||
MAX(threads.title) FILTER (WHERE threads.created_at = latest.created_at) AS latest_thread_title,
|
||||
MAX(threads.slug) FILTER (WHERE threads.created_at = latest.created_at) AS latest_thread_slug
|
||||
FROM users
|
||||
LEFT JOIN posts ON posts.user_id = users.id
|
||||
LEFT JOIN threads ON threads.user_id = users.id
|
||||
LEFT JOIN (
|
||||
SELECT user_id, MAX(created_at) AS created_at
|
||||
FROM threads
|
||||
GROUP BY user_id
|
||||
) latest ON latest.user_id = users.id
|
||||
WHERE users.id = ?"""
|
||||
return db.fetch_one(q, self.id)
|
||||
|
||||
class Topics(Model):
|
||||
table = "topics"
|
||||
|
||||
|
Reference in New Issue
Block a user