add comment count column to submissions
ALTER TABLE submissions add column comment_count integer default 0; update submissions set comment_count=(select count(id) from comments where parent_submission=submissions.id);
This commit is contained in:
parent
428fee9854
commit
33d58691f9
2 changed files with 7 additions and 5 deletions
|
@ -52,6 +52,7 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
|
|||
stickied = Column(Boolean, default=False)
|
||||
is_pinned = Column(Boolean, default=False)
|
||||
private = Column(Boolean, default=False)
|
||||
comment_count = Column(Integer, default=0)
|
||||
comments = relationship(
|
||||
"Comment",
|
||||
lazy="joined",
|
||||
|
@ -95,11 +96,6 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
|
|||
def __repr__(self):
|
||||
return f"<Submission(id={self.id})>"
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def comment_count(self):
|
||||
return len(self.comments)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def score(self):
|
||||
|
|
|
@ -269,8 +269,14 @@ def api_comment(v):
|
|||
app_id=v.client.application.id if v.client else None,
|
||||
shadowbanned=v.shadowbanned
|
||||
)
|
||||
|
||||
g.db.add(c)
|
||||
g.db.flush()
|
||||
|
||||
parent_post.comment_count = g.db.query(Comment).filter_by(parent_submission=parent_post.id).count()
|
||||
g.db.add(parent_post)
|
||||
g.db.flush()
|
||||
|
||||
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
|
||||
file=request.files["file"]
|
||||
if not file.content_type.startswith('image/'): return {"error": "That wasn't an image!"}, 400
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue