mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-09 21:02:24 +01:00
Cache end-response when searching songs
This commit is contained in:
@ -111,18 +111,17 @@ def songs(request):
|
|||||||
except EmptyPage:
|
except EmptyPage:
|
||||||
songs = paginator.page(paginator.num_pages)
|
songs = paginator.page(paginator.num_pages)
|
||||||
|
|
||||||
return [song_to_dict(song, user=True) for song in songs.object_list], paginator
|
songs_dict = [song_to_dict(song, user=True) for song in songs.object_list]
|
||||||
|
|
||||||
cache_key = '|'.join(request.POST.get(k) for k in ('all', 'uploader', 'pagesize', 'page'))
|
|
||||||
songs_dict, paginator = caches['song_search'].get_or_set(cache_key, search_songs, 60*60*2)
|
|
||||||
|
|
||||||
return JsonResponse({
|
return JsonResponse({
|
||||||
'per_page': pagesize,
|
'per_page': pagesize,
|
||||||
'current_page': page,
|
'current_page': page,
|
||||||
'last_page': paginator.num_pages,
|
'last_page': paginator.num_pages,
|
||||||
'data': songs_dict
|
'data': songs_dict,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
cache_key = '|'.join(request.POST.get(k, '') for k in ('all', 'uploader', 'pagesize', 'page'))
|
||||||
|
return caches['song_search'].get_or_set(cache_key, search_songs, 60*60*2)
|
||||||
|
|
||||||
|
|
||||||
@api_auth_required
|
@api_auth_required
|
||||||
def managesongs(request):
|
def managesongs(request):
|
||||||
@ -277,6 +276,9 @@ def upload(request):
|
|||||||
song = Song(user=request.user, artist=artists[i], title=titles[i], hash=hash, duration=duration)
|
song = Song(user=request.user, artist=artists[i], title=titles[i], hash=hash, duration=duration)
|
||||||
song.save()
|
song.save()
|
||||||
|
|
||||||
|
# Clear the search cache
|
||||||
|
caches['song_search'].clear()
|
||||||
|
|
||||||
upload_counter.inc()
|
upload_counter.inc()
|
||||||
return JsonResponse({'success': True})
|
return JsonResponse({'success': True})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user