feature:gzip

This commit is contained in:
charlesxie
2023-06-08 13:14:21 +08:00
parent 1f1721aa00
commit 13f0be7204
4 changed files with 21 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
import collections
import time
from django.db.models import Count, functions, Sum
from rest_framework import serializers
@@ -149,7 +150,6 @@ def get_album2_data(album):
"""
subsonic expects this kind of data:
"""
payload = {
"id": album.id,
"artistId": album.artist_id,

View File

@@ -1,9 +1,11 @@
import random
import urllib.parse
from datetime import datetime
from django.conf import settings
from rest_framework.response import Response
from applications.music.models import Track, Album
from applications.subsonic.constants import EXTENSION_TO_MIMETYPE
@@ -40,3 +42,14 @@ def handle_serve(
response["Content-Type"] = mt
return response
def mock_track():
alnum = Album.objects.order_by("?").first()
for i in range(150):
Track.objects.create(
name="test2",
album_id=alnum.id
)
print(i)

View File

@@ -7,6 +7,8 @@ import time
from django.conf import settings
from django.db.models import Count
from django.utils import timezone
from django.utils.decorators import method_decorator
from django.views.decorators.gzip import gzip_page
from rest_framework import exceptions
from rest_framework import permissions as rest_permissions
from rest_framework import response, viewsets
@@ -18,6 +20,7 @@ from .serializers import PassSerializers
from .utils import handle_serve
@method_decorator(gzip_page, name="dispatch")
class SubsonicViewSet(viewsets.GenericViewSet):
content_negotiation_class = negotiation.SubsonicContentNegociation
authentication_classes = [authentication.SubsonicAuthentication]
@@ -330,7 +333,7 @@ class SubsonicViewSet(viewsets.GenericViewSet):
data = {"albumList2": {"album": serializers.get_album_list2_data(queryset)}}
print("耗时", time.time() - a)
print("sql", len(connection.queries), connection.queries)
print("sql", len(connection.queries), [i["time"] for i in connection.queries])
return response.Response(data)
@action(

View File

@@ -174,19 +174,15 @@ SUBSONIC_DEFAULT_TRANSCODING_FORMAT = "mp3"
SIMPLEUI_DEFAULT_THEME = 'ant.design.css'
SIMPLEUI_HOME_PAGE = '/'
SIMPLEUI_HOME_TITLE = '首页'
# SIMPLEUI_LOGO = "/static/dist/img/music-tag.png"
SIMPLEUI_ANALYSIS = False
SIMPLEUI_CONFIG = {
'system_keep': False,
'menu_display': ['首页', '音乐管理', '用户管理', "Swagger文档"],
'menu_display': ['首页', '音乐管理', '用户管理'],
'dynamic': False,
'menus': [
{
'name': 'Swagger文档',
'icon': 'fa fa-fw fa-home',
"newTab": False,
"url": "/docs/"
},
{
'name': '用户管理',
'icon': 'fa fa-fw fa-home',