From abbbf42715400948e0c69238976a74e1b914c44d Mon Sep 17 00:00:00 2001 From: insects Date: Mon, 31 Mar 2025 23:38:45 +0200 Subject: [PATCH] fix: properly find the most recent pop Closes #2. --- app/controllers/instance_controller.rb | 2 +- app/views/instance/_list.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/instance_controller.rb b/app/controllers/instance_controller.rb index 1817f92..42effa1 100644 --- a/app/controllers/instance_controller.rb +++ b/app/controllers/instance_controller.rb @@ -99,7 +99,7 @@ class InstanceController < ApplicationController parent_instance = Instance.find_by(public_id: instance_id) if params[:mins] && params[:mins].to_i < 120 && params[:pwd] == parent_instance.password ts = Time.now.utc - pop = Pop.find_by(instance_id: parent_instance.id, name: nm) + pop = Pop.find_by(instance_id: parent_instance.id, name: nm, created_at: 120.minutes.ago..Time.now) pop.created_at = Time.at(ts - params[:mins].to_i.minutes).utc pop.save @instance = Instance.includes(:pops, :fairies).find_by(public_id: instance_id) diff --git a/app/views/instance/_list.html.erb b/app/views/instance/_list.html.erb index 6630721..a14b30e 100644 --- a/app/views/instance/_list.html.erb +++ b/app/views/instance/_list.html.erb @@ -46,7 +46,7 @@
<% if nm[:is_popped] %>
- <% pop = instance.pops.find { |pop| pop.name == nm[:name].parameterize } %> + <% pop = instance.pops.find { |pop| (Time.now.utc - 120.minutes) <= pop.created_at and pop.name == nm[:name].parameterize } %> <% mins = ActiveSupport::Duration.build(Time.current - pop.created_at) %>
ยป <%= (120.minutes - mins).in_minutes.ceil %>m