Revert "shorter code"

This reverts commit e8374fb515.
master
Aevann 2024-02-16 01:12:53 +02:00
parent e8374fb515
commit 1dfd4e1e06
11 changed files with 20 additions and 20 deletions

View File

@ -36,7 +36,7 @@ class Group(Base):
@property @property
@lazy @lazy
def member_ids(self): def member_ids(self):
return {x.user_id for x in self.memberships if x.approved_utc} return set(x.user_id for x in self.memberships if x.approved_utc)
@property @property
@lazy @lazy

View File

@ -614,8 +614,8 @@ class User(Base):
@property @property
@lazy @lazy
def all_twoway_blocks(self): def all_twoway_blocks(self):
return {x[0] for x in g.db.query(UserBlock.target_id).filter_by(user_id=self.id).all() + \ return set([x[0] for x in g.db.query(UserBlock.target_id).filter_by(user_id=self.id).all() + \
g.db.query(UserBlock.user_id).filter_by(target_id=self.id).all()} g.db.query(UserBlock.user_id).filter_by(target_id=self.id).all()])
def validate_2fa(self, token): def validate_2fa(self, token):
@ -1109,7 +1109,7 @@ class User(Base):
@property @property
@lazy @lazy
def muters(self): def muters(self):
return {[0] for x in g.db.query(UserMute.user_id).filter_by(target_id=self.id)} return set(x[0] for x in g.db.query(UserMute.user_id).filter_by(target_id=self.id))
def get_relationship_count(self, relationship_cls): def get_relationship_count(self, relationship_cls):

View File

@ -154,10 +154,10 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, obj=None, followers_ping=Tr
if word in text: if word in text:
notify_users.add(id) notify_users.add(id)
names = {m.group(1) for m in mention_regex.finditer(text)} names = set(m.group(1) for m in mention_regex.finditer(text))
if oldtext: if oldtext:
oldnames = {m.group(1) for m in mention_regex.finditer(oldtext)} oldnames = set(m.group(1) for m in mention_regex.finditer(oldtext))
names = names - oldnames names = names - oldnames
user_ids = get_users(names, ids_only=True, graceful=True) user_ids = get_users(names, ids_only=True, graceful=True)
@ -193,22 +193,22 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, obj=None, followers_ping=Tr
return 'everyone' return 'everyone'
elif i.group(1) == 'jannies': elif i.group(1) == 'jannies':
group = None group = None
member_ids = {[0] for x in g.db.query(User.id).filter(User.admin_level > 0, User.id != AEVANN_ID)} member_ids = set(x[0] for x in g.db.query(User.id).filter(User.admin_level > 0, User.id != AEVANN_ID))
elif i.group(1) == 'holejannies': elif i.group(1) == 'holejannies':
if not get_obj_hole(obj): if not get_obj_hole(obj):
abort(403, "!holejannies can only be used inside holes!") abort(403, "!holejannies can only be used inside holes!")
group = None group = None
member_ids = {[0] for x in g.db.query(Mod.user_id).filter_by(hole=obj.hole)} member_ids = set(x[0] for x in g.db.query(Mod.user_id).filter_by(hole=obj.hole))
elif i.group(1) == 'followers': elif i.group(1) == 'followers':
if not followers_ping: if not followers_ping:
abort(403, f"You can't use !followers in posts!") abort(403, f"You can't use !followers in posts!")
group = None group = None
member_ids = {[0] for x in g.db.query(Follow.user_id).filter_by(target_id=v.id)} member_ids = set(x[0] for x in g.db.query(Follow.user_id).filter_by(target_id=v.id))
elif i.group(1) == 'commenters': elif i.group(1) == 'commenters':
if not commenters_ping_post_id: if not commenters_ping_post_id:
abort(403, "You can only use !commenters in comments made under posts!") abort(403, "You can only use !commenters in comments made under posts!")
group = None group = None
member_ids = {[0] for x in g.db.query(User.id).join(Comment, Comment.author_id == User.id).filter(Comment.parent_post == commenters_ping_post_id)} - {v.id} member_ids = set(x[0] for x in g.db.query(User.id).join(Comment, Comment.author_id == User.id).filter(Comment.parent_post == commenters_ping_post_id)) - {v.id}
else: else:
group = g.db.get(Group, i.group(1)) group = g.db.get(Group, i.group(1))
if not group: continue if not group: continue
@ -242,7 +242,7 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, obj=None, followers_ping=Tr
abort(403, "You can only notify a maximum of 400 users.") abort(403, "You can only notify a maximum of 400 users.")
if v.shadowbanned or (obj and obj.is_banned): if v.shadowbanned or (obj and obj.is_banned):
notify_users = {x[0] for x in g.db.query(User.id).filter(User.id.in_(notify_users), User.admin_level >= PERMS['USER_SHADOWBAN']).all()} notify_users = set(x[0] for x in g.db.query(User.id).filter(User.id.in_(notify_users), User.admin_level >= PERMS['USER_SHADOWBAN']).all())
return notify_users - BOT_IDs - {v.id, 0} - v.all_twoway_blocks - v.muters return notify_users - BOT_IDs - {v.id, 0} - v.all_twoway_blocks - v.muters

View File

@ -1166,7 +1166,7 @@ from sqlalchemy.orm import scoped_session, sessionmaker
engine = create_engine(environ.get("DATABASE_URL").strip(), connect_args={"options": "-c statement_timeout=10000 -c idle_in_transaction_session_timeout=40000"}) engine = create_engine(environ.get("DATABASE_URL").strip(), connect_args={"options": "-c statement_timeout=10000 -c idle_in_transaction_session_timeout=40000"})
db_session = scoped_session(sessionmaker(bind=engine, autoflush=False)) db_session = scoped_session(sessionmaker(bind=engine, autoflush=False))
approved_embed_hosts_for_csp = ' '.join({x.split('/')[0] for x in approved_embed_hosts}) approved_embed_hosts_for_csp = ' '.join(set(x.split('/')[0] for x in approved_embed_hosts))
csp = f"default-src 'none'; frame-ancestors 'none'; form-action 'self'; manifest-src 'self'; worker-src 'self'; base-uri 'self'; font-src 'self'; style-src-elem 'self' rdrama.net watchpeopledie.tv; style-src-attr 'unsafe-inline'; style-src 'self' 'unsafe-inline'; script-src-elem 'self' challenges.cloudflare.com static.cloudflareinsights.com; script-src-attr 'none'; script-src 'self' challenges.cloudflare.com static.cloudflareinsights.com; frame-src challenges.cloudflare.com cdpn.io platform.twitter.com rumble.com player.twitch.tv; connect-src 'self' videos.watchpeopledie.tv; img-src {approved_embed_hosts_for_csp} data:; media-src {approved_embed_hosts_for_csp};" csp = f"default-src 'none'; frame-ancestors 'none'; form-action 'self'; manifest-src 'self'; worker-src 'self'; base-uri 'self'; font-src 'self'; style-src-elem 'self' rdrama.net watchpeopledie.tv; style-src-attr 'unsafe-inline'; style-src 'self' 'unsafe-inline'; script-src-elem 'self' challenges.cloudflare.com static.cloudflareinsights.com; script-src-attr 'none'; script-src 'self' challenges.cloudflare.com static.cloudflareinsights.com; frame-src challenges.cloudflare.com cdpn.io platform.twitter.com rumble.com player.twitch.tv; connect-src 'self' videos.watchpeopledie.tv; img-src {approved_embed_hosts_for_csp} data:; media-src {approved_embed_hosts_for_csp};"
if not IS_LOCALHOST: if not IS_LOCALHOST:
csp += ' upgrade-insecure-requests;' csp += ' upgrade-insecure-requests;'

View File

@ -246,7 +246,7 @@ def _leaderboard_task():
def _process_timer(attr, badge_ids, text, extra_attrs={}): def _process_timer(attr, badge_ids, text, extra_attrs={}):
now = time.time() now = time.time()
users = g.db.query(User).options(load_only(User.id)).filter(1 < attr, attr < now) users = g.db.query(User).options(load_only(User.id)).filter(1 < attr, attr < now)
uids = {x.id for x in users} uids = set(x.id for x in users)
#set user attributes #set user attributes
attr = str(attr).split('.')[1] attr = str(attr).split('.')[1]

View File

@ -100,7 +100,7 @@ def get_account(id, v=None, graceful=False, include_blocks=False):
def get_accounts_dict(ids, v=None, graceful=False): def get_accounts_dict(ids, v=None, graceful=False):
if not ids: return {} if not ids: return {}
try: try:
ids = {int(id) for id in ids} ids = set(int(id) for id in ids)
except: except:
if graceful: return None if graceful: return None
abort(400, "User IDs need to be an integer.") abort(400, "User IDs need to be an integer.")

View File

@ -363,7 +363,7 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=False, count_emojis
sanitized = reddit_mention_regex.sub(r'\1<a href="https://old.reddit.com/\2" rel="nofollow noopener" target="_blank">/\2</a>', sanitized) sanitized = reddit_mention_regex.sub(r'\1<a href="https://old.reddit.com/\2" rel="nofollow noopener" target="_blank">/\2</a>', sanitized)
sanitized = hole_mention_regex.sub(r'<a href="/\1">/\1</a>', sanitized) sanitized = hole_mention_regex.sub(r'<a href="/\1">/\1</a>', sanitized)
names = {m.group(1) for m in mention_regex.finditer(sanitized)} names = set(m.group(1) for m in mention_regex.finditer(sanitized))
if limit_pings and len(names) > limit_pings and v.admin_level < PERMS['POST_COMMENT_INFINITE_PINGS']: if limit_pings and len(names) > limit_pings and v.admin_level < PERMS['POST_COMMENT_INFINITE_PINGS']:
return error("Max ping limit is 5 for comments and 50 for posts!") return error("Max ping limit is 5 for comments and 50 for posts!")

View File

@ -984,7 +984,7 @@ def hole_log(v, hole):
if mod_id: if mod_id:
actions = actions.filter_by(user_id=mod_id) actions = actions.filter_by(user_id=mod_id)
kinds = {x.kind for x in actions} kinds = set(x.kind for x in actions)
if kind: kinds.add(kind) if kind: kinds.add(kind)
types2 = {} types2 = {}
for k,val in types.items(): for k,val in types.items():

View File

@ -216,7 +216,7 @@ def post_id(pid, v, anything=None, hole=None):
def view_more(v, pid, sort, offset): def view_more(v, pid, sort, offset):
p = get_post(pid, v=v) p = get_post(pid, v=v)
try: ids = {int(x) for x in request.values.get("ids").split(',')} try: ids = set(int(x) for x in request.values.get("ids").split(','))
except: abort(400) except: abort(400)
if v: if v:

View File

@ -44,7 +44,7 @@ def get_alt_graph_ids(uid):
) )
alt_graph_cte = alt_graph_cte.union(alt_graph_cte_inner) alt_graph_cte = alt_graph_cte.union(alt_graph_cte_inner)
return {x[0] for x in g.db.query(User.id).filter(User.id == alt_graph_cte.c.user_id, User.id != uid)} return set(x[0] for x in g.db.query(User.id).filter(User.id == alt_graph_cte.c.user_id, User.id != uid))
def get_alt_graph(uid): def get_alt_graph(uid):
alt_ids = get_alt_graph_ids(uid) alt_ids = get_alt_graph_ids(uid)
@ -74,7 +74,7 @@ def check_for_alts(current, include_current_session=False):
if session.get("GLOBAL"): if session.get("GLOBAL"):
return return
past_accs = {session.get("history", [])} if include_current_session else set() past_accs = set(session.get("history", [])) if include_current_session else set()
if current.email and current.email_verified: if current.email and current.email_verified:
more_ids = [x[0] for x in g.db.query(User.id).filter( more_ids = [x[0] for x in g.db.query(User.id).filter(

View File

@ -217,7 +217,7 @@ def log(v):
actions = actions.filter(ModAction.kind.notin_(MODACTION_PRIVILEGED__TYPES)) actions = actions.filter(ModAction.kind.notin_(MODACTION_PRIVILEGED__TYPES))
if admin_id: if admin_id:
actions = actions.filter_by(user_id=admin_id) actions = actions.filter_by(user_id=admin_id)
kinds = {x.kind for x in actions} kinds = set(x.kind for x in actions)
kinds.add(kind) kinds.add(kind)
types2 = {} types2 = {}
for k,val in types.items(): for k,val in types.items():