Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Auri
funkwhale
Commits
9d55320b
Verified
Commit
9d55320b
authored
Dec 27, 2018
by
Eliot Berriot
Browse files
Fixed slow query on domain list / stats
parent
3f5d363f
Changes
5
Hide whitespace changes
Inline
Side-by-side
api/funkwhale_api/federation/models.py
View file @
9d55320b
...
...
@@ -66,15 +66,6 @@ class DomainQuerySet(models.QuerySet):
def
external
(
self
):
return
self
.
exclude
(
pk
=
settings
.
FEDERATION_HOSTNAME
)
def
with_last_activity_date
(
self
):
activities
=
Activity
.
objects
.
filter
(
actor__domain
=
models
.
OuterRef
(
"pk"
)
).
order_by
(
"-creation_date"
)
return
self
.
annotate
(
last_activity_date
=
models
.
Subquery
(
activities
.
values
(
"creation_date"
)[:
1
])
)
def
with_actors_count
(
self
):
return
self
.
annotate
(
actors_count
=
models
.
Count
(
"actors"
,
distinct
=
True
))
...
...
@@ -111,7 +102,6 @@ class Domain(models.Model):
actors
=
models
.
Count
(
"actors"
,
distinct
=
True
),
outbox_activities
=
models
.
Count
(
"actors__outbox_activities"
,
distinct
=
True
),
libraries
=
models
.
Count
(
"actors__libraries"
,
distinct
=
True
),
uploads
=
models
.
Count
(
"actors__libraries__uploads"
,
distinct
=
True
),
received_library_follows
=
models
.
Count
(
"actors__libraries__received_follows"
,
distinct
=
True
),
...
...
@@ -130,6 +120,7 @@ class Domain(models.Model):
).
count
()
uploads
=
music_models
.
Upload
.
objects
.
filter
(
library__actor__domain_id
=
self
.
pk
)
data
[
"uploads"
]
=
uploads
.
count
()
data
[
"media_total_size"
]
=
uploads
.
aggregate
(
v
=
models
.
Sum
(
"size"
))[
"v"
]
or
0
data
[
"media_downloaded_size"
]
=
(
uploads
.
with_file
().
aggregate
(
v
=
models
.
Sum
(
"size"
))[
"v"
]
or
0
...
...
api/funkwhale_api/manage/serializers.py
View file @
9d55320b
...
...
@@ -173,7 +173,6 @@ class ManageInvitationActionSerializer(common_serializers.ActionSerializer):
class
ManageDomainSerializer
(
serializers
.
ModelSerializer
):
actors_count
=
serializers
.
SerializerMethodField
()
last_activity_date
=
serializers
.
SerializerMethodField
()
outbox_activities_count
=
serializers
.
SerializerMethodField
()
class
Meta
:
...
...
@@ -182,7 +181,6 @@ class ManageDomainSerializer(serializers.ModelSerializer):
"name"
,
"creation_date"
,
"actors_count"
,
"last_activity_date"
,
"outbox_activities_count"
,
"nodeinfo"
,
"nodeinfo_fetch_date"
,
...
...
@@ -191,8 +189,5 @@ class ManageDomainSerializer(serializers.ModelSerializer):
def
get_actors_count
(
self
,
o
):
return
getattr
(
o
,
"actors_count"
,
0
)
def
get_last_activity_date
(
self
,
o
):
return
getattr
(
o
,
"last_activity_date"
,
None
)
def
get_outbox_activities_count
(
self
,
o
):
return
getattr
(
o
,
"outbox_activities_count"
,
0
)
api/funkwhale_api/manage/views.py
View file @
9d55320b
...
...
@@ -102,7 +102,6 @@ class ManageDomainViewSet(
lookup_value_regex
=
r
"[a-zA-Z0-9\-\.]+"
queryset
=
(
federation_models
.
Domain
.
objects
.
external
()
.
with_last_activity_date
()
.
with_actors_count
()
.
with_outbox_activities_count
()
.
order_by
(
"name"
)
...
...
@@ -114,7 +113,7 @@ class ManageDomainViewSet(
ordering_fields
=
[
"name"
,
"creation_date"
,
"
last_activity
_date"
,
"
nodeinfo_fetch
_date"
,
"actors_count"
,
"outbox_activities_count"
,
]
...
...
api/tests/manage/test_serializers.py
View file @
9d55320b
...
...
@@ -40,11 +40,9 @@ def test_manage_domain_serializer(factories, now):
domain
=
factories
[
"federation.Domain"
]()
setattr
(
domain
,
"actors_count"
,
42
)
setattr
(
domain
,
"outbox_activities_count"
,
23
)
setattr
(
domain
,
"last_activity_date"
,
now
)
expected
=
{
"name"
:
domain
.
name
,
"creation_date"
:
domain
.
creation_date
.
isoformat
().
split
(
"+"
)[
0
]
+
"Z"
,
"last_activity_date"
:
now
,
"actors_count"
:
42
,
"outbox_activities_count"
:
23
,
"nodeinfo"
:
{},
...
...
front/src/components/manage/moderation/DomainsTable.vue
View file @
9d55320b
...
...
@@ -38,7 +38,6 @@
<th><translate>
Users
</translate></th>
<th><translate>
Received messages
</translate></th>
<th><translate>
First seen
</translate></th>
<th><translate>
Last activity
</translate></th>
</
template
>
<
template
slot=
"row-cells"
slot-scope=
"scope"
>
<td>
...
...
@@ -53,10 +52,6 @@
<td>
<human-date
:date=
"scope.obj.creation_date"
></human-date>
</td>
<td>
<human-date
v-if=
"scope.obj.last_activity_date"
:date=
"scope.obj.last_activity_date"
></human-date>
<translate
v-else
>
N/A
</translate>
</td>
</
template
>
</action-table>
</div>
...
...
@@ -112,7 +107,6 @@ export default {
orderingOptions
:
[
[
'
name
'
,
'
name
'
],
[
'
creation_date
'
,
'
first_seen
'
],
[
'
last_activity_date
'
,
'
last_activity
'
],
[
'
actors_count
'
,
'
users
'
],
[
'
outbox_activities_count
'
,
'
received_messages
'
]
]
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment