Skip to content

Commit f356aca

Browse files
authored
Clear search cache (#811)
* implement the cache cleanup * fix title * linting
1 parent de42a63 commit f356aca

File tree

5 files changed

+131
-6
lines changed

5 files changed

+131
-6
lines changed

src/templates/users/about.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% load static %}
55

66
{% block title %}
7-
Account - Yamtrack
7+
About - Yamtrack
88
{% endblock title %}
99

1010
{% block settings_content %}

src/templates/users/advanced.html

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{% extends "users/base.html" %}
2+
3+
{% load socialaccount %}
4+
{% load static %}
5+
6+
{% block title %}
7+
Advanced - Yamtrack
8+
{% endblock title %}
9+
10+
{% block settings_content %}
11+
12+
<div class="space-y-6">
13+
<div class="bg-[#2a2f35] rounded-lg p-6">
14+
<div class="flex items-center mb-5">
15+
<svg xmlns="http://www.w3.org/2000/svg"
16+
width="24"
17+
height="24"
18+
viewBox="0 0 24 24"
19+
fill="none"
20+
stroke="currentColor"
21+
stroke-width="2"
22+
stroke-linecap="round"
23+
stroke-linejoin="round"
24+
class="w-6 h-6 text-indigo-400 mr-3">
25+
<line x1="4" x2="4" y1="21" y2="14" /><line x1="4" x2="4" y1="10" y2="3" /><line x1="12" x2="12" y1="21" y2="12" /><line x1="12" x2="12" y1="8" y2="3" /><line x1="20" x2="20" y1="21" y2="16" /><line x1="20" x2="20" y1="12" y2="3" /><line x1="2" x2="6" y1="14" y2="14" /><line x1="10" x2="14" y1="8" y2="8" /><line x1="18" x2="22" y1="16" y2="16" />
26+
</svg>
27+
<h2 class="text-xl font-semibold">Advanced</h2>
28+
</div>
29+
30+
<div class="bg-[#39404b] p-5 rounded-lg mb-6">
31+
<div class="flex items-center mb-3">
32+
<svg xmlns="http://www.w3.org/2000/svg"
33+
width="24"
34+
height="24"
35+
viewBox="0 0 24 24"
36+
fill="none"
37+
stroke="currentColor"
38+
stroke-width="2"
39+
stroke-linecap="round"
40+
stroke-linejoin="round"
41+
class="w-5 h-5 text-indigo-400 mr-2">
42+
<path d="M10 11v6" />
43+
<path d="M14 11v6" />
44+
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" />
45+
<path d="M3 6h18" />
46+
<path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
47+
</svg>
48+
<h3 class="text-base font-medium">Clear Search Cache</h3>
49+
</div>
50+
<p class="text-gray-400 mb-4 text-sm">
51+
Yamtrack stores your search results in a cache to speed up performance and reduce API calls.
52+
<br>
53+
Normally, these cached results expire automatically after 24 hours.
54+
If your search results appear outdated, you can clear the cache manually.
55+
<br>
56+
Your next search may be slightly slower as fresh data is retrieved.
57+
</p>
58+
<div class="flex space-x-3">
59+
<form method="post" action="{% url 'clear_search_cache' %}">
60+
{% csrf_token %}
61+
<button type="submit"
62+
class="flex items-center px-4 py-2 bg-red-600 text-white rounded-md hover:bg-red-700 transition-colors text-sm cursor-pointer">
63+
<svg xmlns="http://www.w3.org/2000/svg"
64+
width="24"
65+
height="24"
66+
viewBox="0 0 24 24"
67+
fill="none"
68+
stroke="currentColor"
69+
stroke-width="2"
70+
stroke-linecap="round"
71+
stroke-linejoin="round"
72+
class="w-4 h-4 mr-2">
73+
<path d="M10 11v6" />
74+
<path d="M14 11v6" />
75+
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" />
76+
<path d="M3 6h18" />
77+
<path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
78+
</svg>
79+
Clear Search Cache
80+
</button>
81+
</form>
82+
</div>
83+
</div>
84+
</div>
85+
</div>
86+
87+
{% endblock settings_content %}

src/templates/users/base.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,24 @@ <h1 class="text-3xl font-bold">Settings</h1>
133133
<span>Export Data</span>
134134
</a>
135135

136+
{% url 'advanced' as advanced_url %}
137+
<a href="{{ advanced_url }}"
138+
class="w-full flex items-center space-x-3 px-2 py-2 rounded-md transition-colors text-left border-l-2 cursor-pointer text-sm {% if request.path == advanced_url %}bg-[#39404b] text-white border-indigo-500{% else %}text-gray-400 border-transparent hover:bg-[#313842] hover:text-white{% endif %}">
139+
<svg xmlns="http://www.w3.org/2000/svg"
140+
width="24"
141+
height="24"
142+
viewBox="0 0 24 24"
143+
fill="none"
144+
stroke="currentColor"
145+
stroke-width="2"
146+
stroke-linecap="round"
147+
stroke-linejoin="round"
148+
class="w-5 h-5">
149+
<line x1="4" x2="4" y1="21" y2="14" /><line x1="4" x2="4" y1="10" y2="3" /><line x1="12" x2="12" y1="21" y2="12" /><line x1="12" x2="12" y1="8" y2="3" /><line x1="20" x2="20" y1="21" y2="16" /><line x1="20" x2="20" y1="12" y2="3" /><line x1="2" x2="6" y1="14" y2="14" /><line x1="10" x2="14" y1="8" y2="8" /><line x1="18" x2="22" y1="16" y2="16" />
150+
</svg>
151+
<span>Advanced</span>
152+
</a>
153+
136154
{% url 'about' as about_url %}
137155
<a href="{{ about_url }}"
138156
class="w-full flex items-center space-x-3 px-2 py-2 rounded-md transition-colors text-left border-l-2 cursor-pointer text-sm {% if request.path == about_url %}bg-[#39404b] text-white border-indigo-500{% else %}text-gray-400 border-transparent hover:bg-[#313842] hover:text-white{% endif %}">

src/users/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
path("settings/integrations", views.integrations, name="integrations"),
2222
path("settings/import", views.import_data, name="import_data"),
2323
path("settings/export", views.export_data, name="export_data"),
24+
path("settings/advanced", views.advanced, name="advanced"),
2425
path("settings/about", views.about, name="about"),
2526
path(
2627
"delete_import_schedule",
2728
views.delete_import_schedule,
2829
name="delete_import_schedule",
2930
),
3031
path("regenerate_token", views.regenerate_token, name="regenerate_token"),
32+
path("clear_search_cache", views.clear_search_cache, name="clear_search_cache"),
3133
path(
3234
"update_plex_usernames",
3335
views.update_plex_usernames,

src/users/views.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44
from django.conf import settings
55
from django.contrib import messages
66
from django.contrib.auth import update_session_auth_hash
7+
from django.core.cache import cache
78
from django.db import IntegrityError
89
from django.db.models import Q
910
from django.shortcuts import get_object_or_404, redirect, render
11+
from django.template.defaultfilters import pluralize
1012
from django.views.decorators.http import require_GET, require_http_methods, require_POST
1113
from django_celery_beat.models import PeriodicTask
1214

1315
from app.models import Item, MediaTypes
14-
from users.forms import (
15-
NotificationSettingsForm,
16-
PasswordChangeForm,
17-
UserUpdateForm,
18-
)
16+
from users.forms import NotificationSettingsForm, PasswordChangeForm, UserUpdateForm
1917

2018
logger = logging.getLogger(__name__)
2119

@@ -260,6 +258,10 @@ def export_data(request):
260258
"""Render the export data settings page."""
261259
return render(request, "users/export_data.html")
262260

261+
@require_GET
262+
def advanced(request):
263+
"""Render the advanced settings page."""
264+
return render(request, "users/advanced.html")
263265

264266
@require_GET
265267
def about(request):
@@ -317,3 +319,19 @@ def update_plex_usernames(request):
317319
messages.success(request, "Plex usernames updated successfully")
318320

319321
return redirect("integrations")
322+
323+
@require_POST
324+
def clear_search_cache(request):
325+
"""Clear all cached search entries."""
326+
deleted = cache.delete_pattern("search_*")
327+
328+
messages.success(
329+
request,
330+
f"Successfully cleared {deleted} search entr{pluralize(deleted, 'y,ies')}",
331+
)
332+
logger.info(
333+
"Successfully cleared %s search entries",
334+
deleted,
335+
)
336+
337+
return redirect("advanced")

0 commit comments

Comments
 (0)