Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Mélanie Chauvel
funkwhale
Commits
cc71d2bb
Verified
Commit
cc71d2bb
authored
Mar 21, 2019
by
Eliot Berriot
Browse files
Fix #570: Exclude in-place imported files from quota computation
parent
97ef1590
Changes
4
Hide whitespace changes
Inline
Side-by-side
api/funkwhale_api/common/models.py
0 → 100644
View file @
cc71d2bb
from
django.db.models
import
Lookup
from
django.db.models.fields
import
Field
@
Field
.
register_lookup
class
NotEqual
(
Lookup
):
lookup_name
=
"ne"
def
as_sql
(
self
,
compiler
,
connection
):
lhs
,
lhs_params
=
self
.
process_lhs
(
compiler
,
connection
)
rhs
,
rhs_params
=
self
.
process_rhs
(
compiler
,
connection
)
params
=
lhs_params
+
rhs_params
return
"%s <> %s"
%
(
lhs
,
rhs
),
params
api/funkwhale_api/federation/models.py
View file @
cc71d2bb
...
...
@@ -51,11 +51,15 @@ class ActorQuerySet(models.QuerySet):
def
with_current_usage
(
self
):
qs
=
self
for
s
in
[
"pending"
,
"skipped"
,
"errored"
,
"finished"
]:
uploads_query
=
models
.
Q
(
libraries__uploads__import_status
=
s
,
libraries__uploads__audio_file__isnull
=
False
,
libraries__uploads__audio_file__ne
=
""
,
)
qs
=
qs
.
annotate
(
**
{
"_usage_{}"
.
format
(
s
):
models
.
Sum
(
"libraries__uploads__size"
,
filter
=
models
.
Q
(
libraries__uploads__import_status
=
s
),
"libraries__uploads__size"
,
filter
=
uploads_query
)
}
)
...
...
api/tests/federation/test_models.py
View file @
cc71d2bb
...
...
@@ -53,7 +53,25 @@ def test_actor_get_quota(factories):
audio_file__from_path
=
None
,
audio_file__data
=
b
"aaaa"
,
)
expected
=
{
"total"
:
10
,
"pending"
:
1
,
"skipped"
:
2
,
"errored"
:
3
,
"finished"
:
4
}
# this one is imported in place and don't count
factories
[
"music.Upload"
](
library
=
library
,
import_status
=
"finished"
,
source
=
"file://test"
,
audio_file
=
None
,
size
=
42
,
)
# this one is imported in place but count because there is a mapped file
factories
[
"music.Upload"
](
library
=
library
,
import_status
=
"finished"
,
source
=
"file://test2"
,
audio_file__from_path
=
None
,
audio_file__data
=
b
"aaaa"
,
)
expected
=
{
"total"
:
14
,
"pending"
:
1
,
"skipped"
:
2
,
"errored"
:
3
,
"finished"
:
8
}
assert
library
.
actor
.
get_current_usage
()
==
expected
...
...
changes/changelog.d/570.enhancement
0 → 100644
View file @
cc71d2bb
Exclude in-place imported files from quota computation (#570)
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