remove func.lower which was bad for DB perf

This commit is contained in:
rimu 2024-02-10 16:29:03 +13:00
parent 2eadaa5eed
commit 4974d2cddb
3 changed files with 7 additions and 7 deletions

View file

@ -801,7 +801,7 @@ def process_delete_request(request_json, activitypublog_id, ip_address):
with current_app.app_context(): with current_app.app_context():
activity_log = ActivityPubLog.query.get(activitypublog_id) activity_log = ActivityPubLog.query.get(activitypublog_id)
if 'type' in request_json and request_json['type'] == 'Delete': if 'type' in request_json and request_json['type'] == 'Delete':
actor_to_delete = request_json['object'] actor_to_delete = request_json['object'].lower()
user = User.query.filter_by(ap_profile_id=actor_to_delete).first() user = User.query.filter_by(ap_profile_id=actor_to_delete).first()
if user: if user:
# check that the user really has been deleted, to avoid spoofing attacks # check that the user really has been deleted, to avoid spoofing attacks

View file

@ -183,16 +183,16 @@ def instance_allowed(host: str) -> bool:
def find_actor_or_create(actor: str) -> Union[User, Community, None]: def find_actor_or_create(actor: str) -> Union[User, Community, None]:
actor = actor.strip() actor = actor.strip().lower()
user = None user = None
# actor parameter must be formatted as https://server/u/actor or https://server/c/actor # actor parameter must be formatted as https://server/u/actor or https://server/c/actor
# Initially, check if the user exists in the local DB already # Initially, check if the user exists in the local DB already
if current_app.config['SERVER_NAME'] + '/c/' in actor: if current_app.config['SERVER_NAME'] + '/c/' in actor:
return Community.query.filter(func.lower(Community.ap_profile_id) == func.lower(actor)).first() # finds communities formatted like https://localhost/c/* return Community.query.filter(Community.ap_profile_id == actor).first() # finds communities formatted like https://localhost/c/*
if current_app.config['SERVER_NAME'] + '/u/' in actor: if current_app.config['SERVER_NAME'] + '/u/' in actor:
user = User.query.filter(func.lower(User.user_name) == func.lower(actor.split('/')[-1])).filter_by(ap_id=None, banned=False).first() # finds local users user = User.query.filter(func.lower(User.user_name) == actor.split('/')[-1]).filter_by(ap_id=None, banned=False).first() # finds local users
if user is None: if user is None:
return None return None
elif actor.startswith('https://'): elif actor.startswith('https://'):
@ -203,11 +203,11 @@ def find_actor_or_create(actor: str) -> Union[User, Community, None]:
else: else:
if instance_blocked(server): if instance_blocked(server):
return None return None
user = User.query.filter(func.lower(User.ap_profile_id) == func.lower(actor)).first() # finds users formatted like https://kbin.social/u/tables user = User.query.filter(User.ap_profile_id == actor).first() # finds users formatted like https://kbin.social/u/tables
if (user and user.banned) or (user and user.deleted) : if (user and user.banned) or (user and user.deleted) :
return None return None
if user is None: if user is None:
user = Community.query.filter(func.lower(Community.ap_profile_id) == func.lower(actor)).first() user = Community.query.filter(Community.ap_profile_id == actor).first()
if user is not None: if user is not None:
if not user.is_local() and user.ap_fetched_at < utcnow() - timedelta(days=7): if not user.is_local() and user.ap_fetched_at < utcnow() - timedelta(days=7):

View file

@ -116,7 +116,7 @@ def retrieve_mods_and_backfill(community_id: int):
def community_url_exists(url) -> bool: def community_url_exists(url) -> bool:
community = Community.query.filter(func.lower(Community.ap_profile_id) == func.lower(url)).first() community = Community.query.filter(Community.ap_profile_id == url.lower()).first()
return community is not None return community is not None