mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-09 19:52:20 +01:00
Cache end-response when searching songs
This commit is contained in:
@ -111,18 +111,17 @@ def songs(request):
|
||||
except EmptyPage:
|
||||
songs = paginator.page(paginator.num_pages)
|
||||
|
||||
return [song_to_dict(song, user=True) for song in songs.object_list], paginator
|
||||
|
||||
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)
|
||||
|
||||
songs_dict = [song_to_dict(song, user=True) for song in songs.object_list]
|
||||
return JsonResponse({
|
||||
'per_page': pagesize,
|
||||
'current_page': page,
|
||||
'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
|
||||
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.save()
|
||||
|
||||
# Clear the search cache
|
||||
caches['song_search'].clear()
|
||||
|
||||
upload_counter.inc()
|
||||
return JsonResponse({'success': True})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user