From 375600b382bd0d077b55160e2a9c2b5eb21f9ca8 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sat, 10 Feb 2024 11:42:18 +1300 Subject: [PATCH] stats --- app/activitypub/util.py | 4 ++-- app/main/routes.py | 9 +++++++++ app/models.py | 22 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index e87dd99d..2b9b77d1 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -350,7 +350,7 @@ def actor_json_to_model(activity_json, address, server): created=activity_json['published'] if 'published' in activity_json else utcnow(), ap_id=f"{address}@{server}", ap_public_url=activity_json['id'], - ap_profile_id=activity_json['id'], + ap_profile_id=activity_json['id'].lower(), ap_inbox_url=activity_json['endpoints']['sharedInbox'], ap_followers_url=activity_json['followers'] if 'followers' in activity_json else None, ap_preferred_username=activity_json['preferredUsername'], @@ -404,7 +404,7 @@ def actor_json_to_model(activity_json, address, server): last_active=activity_json['updated'] if 'updated' in activity_json else utcnow(), ap_id=f"{address[1:]}@{server}" if address.startswith('!') else f"{address}@{server}", ap_public_url=activity_json['id'], - ap_profile_id=activity_json['id'], + ap_profile_id=activity_json['id'].lower(), ap_followers_url=activity_json['followers'], ap_inbox_url=activity_json['endpoints']['sharedInbox'], ap_moderators_url=mods_url, diff --git a/app/main/routes.py b/app/main/routes.py index 340681b2..28e48f6e 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -249,6 +249,15 @@ def keyboard_shortcuts(): @bp.route('/test') def test(): + retval = '' + for user in User.query.all(): + filesize = user.filesize() + num_content = user.num_content() + if filesize > 0 and num_content > 0: + retval += f'{user.id},"{user.ap_id}",{filesize},{num_content}\n' + return retval + + return '' deleted = 0 for user in User.query.all(): if not user.is_local(): diff --git a/app/models.py b/app/models.py index 2145fb49..362e5dce 100644 --- a/app/models.py +++ b/app/models.py @@ -118,6 +118,14 @@ class File(db.Model): if self.thumbnail_path and os.path.isfile(self.thumbnail_path): os.unlink(self.thumbnail_path) + def filesize(self): + size = 0 + if self.file_path and os.path.exists(self.file_path): + size += os.path.getsize(self.file_path) + if self.thumbnail_path and os.path.exists(self.thumbnail_path): + size += os.path.getsize(self.thumbnail_path) + return size + class Topic(db.Model): id = db.Column(db.Integer, primary_key=True) @@ -445,6 +453,20 @@ class User(UserMixin, db.Model): return self.cover.source_url return '' + def filesize(self): + size = 0 + if self.avatar_id: + size += self.avatar.filesize() + if self.cover_id: + size += self.cover.filesize() + return size + + def num_content(self): + content = 0 + content += db.session.execute(text('SELECT COUNT(id) as c FROM "post" WHERE user_id = ' + str(self.id))).scalar() + content += db.session.execute(text('SELECT COUNT(id) as c FROM "post_reply" WHERE user_id = ' + str(self.id))).scalar() + return content + def is_local(self): return self.ap_id is None or self.ap_profile_id.startswith('https://' + current_app.config['SERVER_NAME'])