mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
better queries
This commit is contained in:
parent
1d1abdac6d
commit
2249140bf3
3 changed files with 15 additions and 16 deletions
|
@ -973,8 +973,6 @@ def admin_instances():
|
|||
low_bandwidth = request.cookies.get('low_bandwidth', '0') == '1'
|
||||
|
||||
instances = Instance.query.order_by(Instance.domain)
|
||||
user_model = User
|
||||
community_model = Community
|
||||
|
||||
if search:
|
||||
instances = instances.filter(Instance.domain.ilike(f"%{search}%"))
|
||||
|
@ -990,7 +988,6 @@ def admin_instances():
|
|||
title=_('Instances'), search=search,
|
||||
next_url=next_url, prev_url=prev_url,
|
||||
low_bandwidth=low_bandwidth,
|
||||
user_model=user_model, community_model=community_model,
|
||||
moderating_communities=moderating_communities(current_user.get_id()),
|
||||
joined_communities=joined_communities(current_user.get_id()),
|
||||
menu_topics=menu_topics(), site=g.site)
|
||||
|
@ -1004,8 +1001,6 @@ def admin_instances_dormant():
|
|||
low_bandwidth = request.cookies.get('low_bandwidth', '0') == '1'
|
||||
|
||||
instances = Instance.query.order_by(Instance.domain)
|
||||
user_model = User
|
||||
community_model = Community
|
||||
|
||||
instances = instances.filter(Instance.dormant == True)
|
||||
|
||||
|
@ -1023,7 +1018,6 @@ def admin_instances_dormant():
|
|||
title=_('Dormant Instances'), search=search,
|
||||
next_url=next_url, prev_url=prev_url,
|
||||
low_bandwidth=low_bandwidth,
|
||||
user_model=user_model, community_model=community_model,
|
||||
moderating_communities=moderating_communities(current_user.get_id()),
|
||||
joined_communities=joined_communities(current_user.get_id()),
|
||||
menu_topics=menu_topics(), site=g.site)
|
||||
|
@ -1037,8 +1031,6 @@ def admin_instances_gone_forever():
|
|||
low_bandwidth = request.cookies.get('low_bandwidth', '0') == '1'
|
||||
|
||||
instances = Instance.query.order_by(Instance.domain)
|
||||
user_model = User
|
||||
community_model = Community
|
||||
|
||||
instances = instances.filter(Instance.gone_forever == True)
|
||||
|
||||
|
@ -1056,7 +1048,6 @@ def admin_instances_gone_forever():
|
|||
title=_('Gone Forever Instances'), search=search,
|
||||
next_url=next_url, prev_url=prev_url,
|
||||
low_bandwidth=low_bandwidth,
|
||||
user_model=user_model, community_model=community_model,
|
||||
moderating_communities=moderating_communities(current_user.get_id()),
|
||||
joined_communities=joined_communities(current_user.get_id()),
|
||||
menu_topics=menu_topics(), site=g.site)
|
|
@ -84,6 +84,18 @@ class Instance(db.Model):
|
|||
def votes_are_public(self):
|
||||
return self.software.lower() == 'lemmy' or self.software.lower() == 'mbin' or self.software.lower() == 'kbin'
|
||||
|
||||
def post_count(self):
|
||||
return db.session.execute(text(f'SELECT count(*) FROM post WHERE instance_id = {self.id}')).all()[0].count
|
||||
|
||||
def post_replies_count(self):
|
||||
return db.session.execute(text(f'SELECT count(*) FROM post_reply WHERE instance_id = {self.id}')).all()[0].count
|
||||
|
||||
def known_communities_count(self):
|
||||
return db.session.execute(text(f'SELECT count(*) FROM community WHERE instance_id = {self.id}')).all()[0].count
|
||||
|
||||
# def known_users_count(self):
|
||||
# return db.session.execute(text(f'SELECT count(DISTINCT instance_id) as count FROM USER')).all()[0].count
|
||||
|
||||
def __repr__(self):
|
||||
return '<Instance {}>'.format(self.domain)
|
||||
|
||||
|
|
|
@ -22,11 +22,9 @@
|
|||
<th>Domain</th>
|
||||
<th>Software</th>
|
||||
<th>Version</th>
|
||||
<th title="{{ _('Known Users') }}">Users</td>
|
||||
<th title="{{ _('Known Communities') }}">Communities</td>
|
||||
<th>Posts</th>
|
||||
<th>Post Replies</th>
|
||||
<th>Communities</th>
|
||||
<th>Vote Weight</th>
|
||||
<th title="{{ _('When an Activity was received from them') }}">Seen</th>
|
||||
<th title="{{ _('When we successfully sent them an Activity') }}">Sent</th>
|
||||
|
@ -38,11 +36,9 @@
|
|||
<td><a href="https://{{ instance.domain }}" rel="noopener nofollow noindex noreferrer">{{ instance.domain }}</a></td>
|
||||
<td>{{ instance.software }}</td>
|
||||
<td>{{ instance.version if instance.version }}</td>
|
||||
<td>{{ len(user_model.query.filter_by(instance_id=instance.id).all()) }}</td>
|
||||
<td>{{ len(community_model.query.filter_by(instance_id=instance.id).all()) }}</td>
|
||||
<td>{{ len(instance.posts.all()) }}</td>
|
||||
<td>{{ len(instance.post_replies.all()) }}</td>
|
||||
<td>{{ len(instance.communities.all()) }}</td>
|
||||
<td>{{ instance.known_communities_count() }}</td>
|
||||
<td>{{ instance.post_count() }}</td>
|
||||
<td>{{ instance.post_replies_count() }}</td>
|
||||
<td>{{ instance.vote_weight }}</td>
|
||||
<td>{{ arrow.get(instance.last_seen).humanize(locale=locale) if instance.last_seen }}</td>
|
||||
<td>{{ arrow.get(instance.last_successful_send).humanize(locale=locale) if instance.last_successful_send }}</td>
|
||||
|
|
Loading…
Add table
Reference in a new issue