Session list: speed up starting new sessions
Django CI/CD / test (push) Successful in 1m1s Details
Django CI/CD / build-and-push (push) Successful in 1m33s Details

This commit is contained in:
Lukáš Kucharczyk 2024-01-10 15:53:15 +01:00
parent 0cf3411f63
commit 44f49e5974
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
3 changed files with 12 additions and 18 deletions

View File

@ -3,7 +3,7 @@
## Improved ## Improved
* game overview: improve how editions and purchases are displayed * game overview: improve how editions and purchases are displayed
* add purchase: only allow choosing purchases of selected edition * add purchase: only allow choosing purchases of selected edition
* session list: clicking the "End now?" link is not much faster * session list: starting and ending sessions is much faster/doest not reload the page
## 1.5.1 / 2023-11-14 21:10+01:00 ## 1.5.1 / 2023-11-14 21:10+01:00

View File

@ -11,7 +11,6 @@
hx-get="{% url 'start_session_same_as_last' last.id %}" hx-get="{% url 'start_session_same_as_last' last.id %}"
hx-swap="afterbegin" hx-swap="afterbegin"
hx-target=".responsive-table tbody" hx-target=".responsive-table tbody"
hx-select=".responsive-table tbody tr:first-child"
onClick="document.querySelector('#last-session-start').classList.add('invisible')" onClick="document.querySelector('#last-session-start').classList.add('invisible')"
class="{% if last.timestamp_end == null %}invisible{% endif %}"> class="{% if last.timestamp_end == null %}invisible{% endif %}">
{% include 'components/button_start.html' with text=last.purchase title="Start session of last played game" only %} {% include 'components/button_start.html' with text=last.purchase title="Start session of last played game" only %}
@ -42,7 +41,7 @@
{{ session.timestamp_start | date:"d/m/Y H:i" }} {{ session.timestamp_start | date:"d/m/Y H:i" }}
</td> </td>
<td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono hidden lg:table-cell"> <td class="px-2 sm:px-4 md:px-6 md:py-2 font-mono hidden lg:table-cell">
{% if session.unfinished %} {% if not session.timestamp_end %}
<a href="{% url 'update_session' session.id %}" <a href="{% url 'update_session' session.id %}"
hx-get="{% url 'update_session' session.id %}" hx-get="{% url 'update_session' session.id %}"
hx-target="closest tr" hx-target="closest tr"

View File

@ -245,15 +245,17 @@ def start_game_session(request, game_id: int):
def start_session_same_as_last(request, last_session_id: int): def start_session_same_as_last(request, last_session_id: int):
last_session = Session.objects.get(id=last_session_id) last_session = get_object_or_404(Session, id=last_session_id)
session = SessionForm( # clone it
{ session = last_session
"purchase": last_session.purchase.id, session.pk = None
"timestamp_start": timezone.now(), # set new data
"device": last_session.device, session.timestamp_start = timezone.now()
} session.timestamp_end = None
)
session.save() session.save()
if request.htmx:
context = {"session": session}
return render(request, "list_sessions.html#session-row", context)
return redirect("list_sessions") return redirect("list_sessions")
@ -301,13 +303,6 @@ def list_sessions(
# by default, sort from newest to oldest # by default, sort from newest to oldest
dataset = Session.objects.order_by("-timestamp_start") dataset = Session.objects.order_by("-timestamp_start")
for session in dataset:
if session.timestamp_end == None and session.duration_manual == timedelta(
seconds=0
):
session.timestamp_end = timezone.now()
session.unfinished = True
context["total_duration"] = dataset.total_duration_formatted() context["total_duration"] = dataset.total_duration_formatted()
context["dataset"] = dataset context["dataset"] = dataset
try: try: