Skip to content
Snippets Groups Projects
Verified Commit cc71d2bb authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Fix #570: Exclude in-place imported files from quota computation

parent 97ef1590
No related branches found
No related tags found
No related merge requests found
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
......@@ -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
)
}
)
......
......@@ -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
......
Exclude in-place imported files from quota computation (#570)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment