Aevann1 2021-09-24 04:00:11 +02:00
parent d6bbdd7c8b
commit 0c9816c185
4 changed files with 39 additions and 119 deletions

View File

@ -13,27 +13,12 @@ import time
site = environ.get("DOMAIN").strip() site = environ.get("DOMAIN").strip()
site_name = environ.get("SITE_NAME").strip() site_name = environ.get("SITE_NAME").strip()
class SubmissionAux(Base):
__tablename__ = "submissions_aux"
key_id = Column(BigInteger, primary_key=True)
id = Column(BigInteger, ForeignKey("submissions.id"))
title = Column(String(500))
title_html = Column(String(500))
url = Column(String(500))
body = deferred(Column(String(10000)))
body_html = deferred(Column(String(20000)))
ban_reason = Column(String(128))
embed_url = Column(String(256))
class Submission(Base): class Submission(Base):
__tablename__ = "submissions" __tablename__ = "submissions"
id = Column(BigInteger, primary_key=True) id = Column(BigInteger, primary_key=True)
submission_aux = relationship("SubmissionAux", uselist=False, primaryjoin="Submission.id==SubmissionAux.id")
author_id = Column(BigInteger, ForeignKey("users.id")) author_id = Column(BigInteger, ForeignKey("users.id"))
edited_utc = Column(BigInteger, default=0) edited_utc = Column(BigInteger, default=0)
created_utc = Column(BigInteger, default=0) created_utc = Column(BigInteger, default=0)
@ -57,15 +42,19 @@ class Submission(Base):
over_18 = Column(Boolean, default=False) over_18 = Column(Boolean, default=False)
author = relationship("User", primaryjoin="Submission.author_id==User.id") author = relationship("User", primaryjoin="Submission.author_id==User.id")
is_bot = Column(Boolean, default=False) is_bot = Column(Boolean, default=False)
upvotes = Column(Integer, default=1) upvotes = Column(Integer, default=1)
downvotes = Column(Integer, default=0) downvotes = Column(Integer, default=0)
app_id=Column(Integer, ForeignKey("oauth_apps.id")) app_id=Column(Integer, ForeignKey("oauth_apps.id"))
title = Column(String(500))
title_html = Column(String(500))
url = Column(String(500))
body = deferred(Column(String(10000)))
body_html = deferred(Column(String(20000)))
ban_reason = Column(String(128))
embed_url = Column(String(256))
oauth_app = relationship("OauthApp", viewonly=True) oauth_app = relationship("OauthApp", viewonly=True)
approved_by = relationship("User", uselist=False, primaryjoin="Submission.is_approved==User.id", viewonly=True) approved_by = relationship("User", uselist=False, primaryjoin="Submission.is_approved==User.id", viewonly=True)
awards = relationship("AwardRelationship", viewonly=True) awards = relationship("AwardRelationship", viewonly=True)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -339,24 +328,6 @@ class Submission(Base):
def award_count(self, kind) -> int: def award_count(self, kind) -> int:
return len([x for x in self.awards if x.kind == kind]) return len([x for x in self.awards if x.kind == kind])
@property
def title(self):
return self.submission_aux.title
@title.setter
def title(self, x):
self.submission_aux.title = x
g.db.add(self.submission_aux)
@property
def url(self):
return self.submission_aux.url
@url.setter
def url(self, x):
self.submission_aux.url = x
g.db.add(self.submission_aux)
@lazy @lazy
def realurl(self, v): def realurl(self, v):
if v and v.agendaposter and random.randint(1, 10) < 4: if v and v.agendaposter and random.randint(1, 10) < 4:
@ -373,27 +344,9 @@ class Submission(Base):
return self.url return self.url
else: return "" else: return ""
@property
def body(self):
return self.submission_aux.body
@body.setter
def body(self, x):
self.submission_aux.body = x
g.db.add(self.submission_aux)
@property
def body_html(self):
return self.submission_aux.body_html
@body_html.setter
def body_html(self, x):
self.submission_aux.body_html = x
g.db.add(self.submission_aux)
def realbody(self, v): def realbody(self, v):
if self.club and not (v and v.paid_dues): return "COUNTRY CLUB ONLY" if self.club and not (v and v.paid_dues): return "COUNTRY CLUB ONLY"
body = self.submission_aux.body_html body = self.body_html
if not v or v.slurreplacer: if not v or v.slurreplacer:
for s,r in SLURS.items(): for s,r in SLURS.items():
@ -403,15 +356,6 @@ class Submission(Base):
if v and v.nitter: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") if v and v.nitter: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net")
return body return body
@property
def title_html(self):
return self.submission_aux.title_html
@title_html.setter
def title_html(self, x):
self.submission_aux.title_html = x
g.db.add(self.submission_aux)
@lazy @lazy
def realtitle(self, v): def realtitle(self, v):
if self.club and not (v and v.paid_dues) and not (v and v.admin_level == 6): return 'COUNTRY CLUB MEMBERS ONLY' if self.club and not (v and v.paid_dues) and not (v and v.admin_level == 6): return 'COUNTRY CLUB MEMBERS ONLY'
@ -423,24 +367,6 @@ class Submission(Base):
return title return title
@property
def ban_reason(self):
return self.submission_aux.ban_reason
@ban_reason.setter
def ban_reason(self, x):
self.submission_aux.ban_reason = x
g.db.add(self.submission_aux)
@property
def embed_url(self):
return self.submission_aux.embed_url
@embed_url.setter
def embed_url(self, x):
self.submission_aux.embed_url = x
g.db.add(self.submission_aux)
@property @property
@lazy @lazy
def is_image(self): def is_image(self):

View File

@ -152,11 +152,11 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='
if not (v and v.changelogsub): if not (v and v.changelogsub):
posts=posts.join(Submission.submission_aux) posts=posts.join(Submission.submission_aux)
posts=posts.filter(not_(SubmissionAux.title.ilike(f'[changelog]%'))) posts=posts.filter(not_(Submission.title.ilike(f'[changelog]%')))
if v and filter_words: if v and filter_words:
for word in filter_words: for word in filter_words:
posts=posts.filter(not_(SubmissionAux.title.ilike(f'%{word}%'))) posts=posts.filter(not_(Submission.title.ilike(f'%{word}%')))
gt = kwargs.get("gt") gt = kwargs.get("gt")
lt = kwargs.get("lt") lt = kwargs.get("lt")
@ -258,7 +258,7 @@ def changeloglist(v=None, sort="new", page=1 ,t="all", **kwargs):
) )
posts=posts.join(Submission.submission_aux).join(Submission.author) posts=posts.join(Submission.submission_aux).join(Submission.author)
posts=posts.filter(SubmissionAux.title.ilike(f'_changelog%', User.admin_level == 6)) posts=posts.filter(Submission.title.ilike(f'_changelog%', User.admin_level == 6))
if t != 'all': if t != 'all':
cutoff = 0 cutoff = 0

View File

@ -617,7 +617,7 @@ def submit_post(v):
url = url.replace("https://streamable.com/", "https://streamable.com/e/") url = url.replace("https://streamable.com/", "https://streamable.com/e/")
repost = g.db.query(Submission).join(Submission.submission_aux).options(lazyload('*')).filter( repost = g.db.query(Submission).join(Submission.submission_aux).options(lazyload('*')).filter(
SubmissionAux.url.ilike(url), Submission.url.ilike(url),
Submission.deleted_utc == 0, Submission.deleted_utc == 0,
Submission.is_banned == False Submission.is_banned == False
).first() ).first()
@ -663,9 +663,9 @@ def submit_post(v):
Submission.author_id == v.id, Submission.author_id == v.id,
Submission.deleted_utc == 0, Submission.deleted_utc == 0,
SubmissionAux.title == title, Submission.title == title,
SubmissionAux.url == url, Submission.url == url,
SubmissionAux.body == body Submission.body == body
).first() ).first()
if dup: if dup:
@ -722,11 +722,11 @@ def submit_post(v):
#or_( #or_(
# and_( # and_(
Submission.author_id == v.id, Submission.author_id == v.id,
SubmissionAux.title.op('<->')(title) < app.config["SPAM_SIMILARITY_THRESHOLD"], Submission.title.op('<->')(title) < app.config["SPAM_SIMILARITY_THRESHOLD"],
Submission.created_utc > cutoff Submission.created_utc > cutoff
# ), # ),
# and_( # and_(
# SubmissionAux.title.op('<->')(title) < app.config["SPAM_SIMILARITY_THRESHOLD"]/2, # Submission.title.op('<->')(title) < app.config["SPAM_SIMILARITY_THRESHOLD"]/2,
# Submission.created_utc > cutoff # Submission.created_utc > cutoff
# ) # )
#) #)
@ -741,11 +741,11 @@ def submit_post(v):
#or_( #or_(
# and_( # and_(
Submission.author_id == v.id, Submission.author_id == v.id,
SubmissionAux.url.op('<->')(url) < app.config["SPAM_URL_SIMILARITY_THRESHOLD"], Submission.url.op('<->')(url) < app.config["SPAM_URL_SIMILARITY_THRESHOLD"],
Submission.created_utc > cutoff Submission.created_utc > cutoff
# ), # ),
# and_( # and_(
# SubmissionAux.url.op('<->')(url) < app.config["SPAM_URL_SIMILARITY_THRESHOLD"]/2, # Submission.url.op('<->')(url) < app.config["SPAM_URL_SIMILARITY_THRESHOLD"]/2,
# Submission.created_utc > cutoff # Submission.created_utc > cutoff
# ) # )
#) #)
@ -863,23 +863,17 @@ def submit_post(v):
over_18=bool(request.values.get("over_18","")), over_18=bool(request.values.get("over_18","")),
app_id=v.client.application.id if v.client else None, app_id=v.client.application.id if v.client else None,
is_bot = request.headers.get("X-User-Type","").lower()=="bot" is_bot = request.headers.get("X-User-Type","").lower()=="bot"
url=url,
body=body,
body_html=body_html,
embed_url=embed,
title=title,
title_html=filter_title(title)
) )
g.db.add(new_post) g.db.add(new_post)
g.db.flush() g.db.flush()
new_post_aux = SubmissionAux(id=new_post.id,
url=url,
body=body,
body_html=body_html,
embed_url=embed,
title=title,
title_html=filter_title(title)
)
g.db.add(new_post_aux)
g.db.flush()
vote = Vote(user_id=v.id, vote = Vote(user_id=v.id,
vote_type=1, vote_type=1,
submission_id=new_post.id submission_id=new_post.id

View File

@ -70,7 +70,7 @@ def searchposts(v):
if 'q' in criteria: if 'q' in criteria:
words=criteria['q'].split() words=criteria['q'].split()
words=[SubmissionAux.title.ilike('%'+x+'%') for x in words] words=[Submission.title.ilike('%'+x+'%') for x in words]
words=tuple(words) words=tuple(words)
posts=posts.filter(*words) posts=posts.filter(*words)
@ -90,18 +90,18 @@ def searchposts(v):
domain=criteria['domain'] domain=criteria['domain']
posts=posts.filter( posts=posts.filter(
or_( or_(
SubmissionAux.url.ilike("https://"+domain+'/%'), Submission.url.ilike("https://"+domain+'/%'),
SubmissionAux.url.ilike("https://"+domain+'/%'), Submission.url.ilike("https://"+domain+'/%'),
SubmissionAux.url.ilike("https://"+domain), Submission.url.ilike("https://"+domain),
SubmissionAux.url.ilike("https://"+domain), Submission.url.ilike("https://"+domain),
SubmissionAux.url.ilike("https://www."+domain+'/%'), Submission.url.ilike("https://www."+domain+'/%'),
SubmissionAux.url.ilike("https://www."+domain+'/%'), Submission.url.ilike("https://www."+domain+'/%'),
SubmissionAux.url.ilike("https://www."+domain), Submission.url.ilike("https://www."+domain),
SubmissionAux.url.ilike("https://www."+domain), Submission.url.ilike("https://www."+domain),
SubmissionAux.url.ilike("https://old." + domain + '/%'), Submission.url.ilike("https://old." + domain + '/%'),
SubmissionAux.url.ilike("https://old." + domain + '/%'), Submission.url.ilike("https://old." + domain + '/%'),
SubmissionAux.url.ilike("https://old." + domain), Submission.url.ilike("https://old." + domain),
SubmissionAux.url.ilike("https://old." + domain) Submission.url.ilike("https://old." + domain)
) )
) )