certified good commit

master
Aevann1 2022-05-25 19:01:29 +02:00
parent b08d374b4b
commit 5b1477acfc
6 changed files with 23 additions and 22 deletions

View File

@ -27,8 +27,7 @@ services:
postgres: postgres:
image: postgres:12.3 image: postgres:12.3
# command: ["postgres", "-c", "log_statement=all"] command: ["postgres", "-c", "log_statement=all"]
# uncomment this if u wanna output all SQL queries to the console
volumes: volumes:
- "./schema.sql:/docker-entrypoint-initdb.d/00-schema.sql" - "./schema.sql:/docker-entrypoint-initdb.d/00-schema.sql"
- "./seed-db.sql:/docker-entrypoint-initdb.d/10-seed-db.sql" - "./seed-db.sql:/docker-entrypoint-initdb.d/10-seed-db.sql"

View File

@ -91,15 +91,12 @@ class Comment(Base):
@property @property
@lazy @lazy
def options(self): def options(self):
li = [x for x in self.child_comments if x.author_id == AUTOPOLLER_ID] return self.child_comments.filter_by(author_id=AUTOPOLLER_ID).order_by(Comment.id).all()
return sorted(li, key=lambda x: x.id)
@property @property
@lazy @lazy
def choices(self): def choices(self):
li = [x for x in self.child_comments if x.author_id == AUTOCHOICE_ID] return self.child_comments.filter_by(author_id=AUTOCHOICE_ID).order_by(Comment.id).all()
return sorted(li, key=lambda x: x.id)
def total_poll_voted(self, v): def total_poll_voted(self, v):
@ -221,15 +218,17 @@ class Comment(Base):
def replies(self): def replies(self):
if self.replies2 != None: return [x for x in self.replies2 if not x.author.shadowbanned] if self.replies2 != None: return [x for x in self.replies2 if not x.author.shadowbanned]
if not self.parent_submission: if not self.parent_submission:
return sorted((x for x in self.child_comments if x.author and not x.author.shadowbanned), key=lambda x: x.created_utc) return self.child_comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None).order_by(Comment.id).all()
return sorted((x for x in self.child_comments if x.author and not x.author.shadowbanned and x.author_id not in (AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID)), key=lambda x: x.realupvotes, reverse=True) return self.child_comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID))).order_by(Comment.realupvotes.desc()).all()
@property @property
def replies3(self): def replies3(self):
if self.replies2 != None: return self.replies2 if self.replies2 != None: return self.replies2
if not self.parent_submission: if not self.parent_submission:
return sorted(self.child_comments, key=lambda x: x.created_utc) return self.child_comments.order_by(Comment.id).all()
return sorted((x for x in self.child_comments if x.author_id not in (AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID)), key=lambda x: x.realupvotes, reverse=True) return self.child_comments.filter(Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID))).order_by(Comment.realupvotes.desc()).all()
@property @property
def replies2(self): def replies2(self):

View File

@ -21,7 +21,7 @@ class Flag(Base):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def __repr__(self): def __repr__(self):
return f"<Flag(id={self.id})>" return f"<Flag(user_id={self.user_id}, post_id={self.post_id})>"
@property @property
@lazy @lazy
@ -54,7 +54,7 @@ class CommentFlag(Base):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def __repr__(self): def __repr__(self):
return f"<CommentFlag(id={self.id})>" return f"<CommentFlag(user_id={self.user_id}, comment_id={self.comment_id})>"
@property @property
@lazy @lazy

View File

@ -20,7 +20,7 @@ class Sub(Base):
bannerurl = Column(String) bannerurl = Column(String)
css = Column(String) css = Column(String)
blocks = relationship("SubBlock", lazy="dynamic", primaryjoin="SubBlock.sub==Sub.name", viewonly=True) blocks = relationship("SubBlock", primaryjoin="SubBlock.sub==Sub.name", viewonly=True)
def __repr__(self): def __repr__(self):
@ -46,4 +46,4 @@ class Sub(Base):
@property @property
@lazy @lazy
def block_num(self): def block_num(self):
return self.blocks.count() return len(self.blocks)

View File

@ -188,7 +188,7 @@ class User(Base):
@property @property
@lazy @lazy
def is_cakeday(self): def is_cakeday(self):
if time.time() - self.created_utc > 365 * 86400: if self.created_utc and time.time() - self.created_utc > 365 * 86400:
if not self.has_badge(134): if not self.has_badge(134):
new_badge = Badge(badge_id=134, user_id=self.id) new_badge = Badge(badge_id=134, user_id=self.id)
g.db.add(new_badge) g.db.add(new_badge)
@ -602,7 +602,7 @@ class User(Base):
@property @property
@lazy @lazy
def applications(self): def applications(self):
return g.db.query(OauthApp).filter_by(author_id=self.id).order_by(OauthApp.id) return g.db.query(OauthApp).filter_by(author_id=self.id).order_by(OauthApp.id).all()
@property @property
@lazy @lazy

View File

@ -1,5 +1,4 @@
# Prevents certain properties from having to be recomputed each time they # Prevents certain properties from having to be recomputed each time they are referenced
# are referenced
def lazy(f): def lazy(f):
@ -8,11 +7,15 @@ def lazy(f):
o = args[0] o = args[0]
if "_lazy" not in o.__dict__: o.__dict__["_lazy"] = {} if "_lazy" not in o.__dict__:
o.__dict__["_lazy"] = {}
if f.__name__ not in o.__dict__["_lazy"]: o.__dict__["_lazy"][f.__name__] = f(*args, **kwargs) name = f.__name__ + str(args) + str(kwargs),
return o.__dict__["_lazy"][f.__name__] if name not in o.__dict__["_lazy"]:
o.__dict__["_lazy"][name] = f(*args, **kwargs)
return o.__dict__["_lazy"][name]
wrapper.__name__ = f.__name__ wrapper.__name__ = f.__name__
return wrapper return wrapper