From 7463cdcc7b59e955bb890b299ae062fce212c9b9 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sun, 12 Apr 2026 17:03:57 -0500 Subject: [PATCH] Cap "Contacts I'm in" at 100 most recent The profile page's involving-contacts query now limits to the 100 most recent rows (ordered by qso_timestamp desc). A small note is shown under the heading when the cap is hit so users know there's more data they're not seeing. --- lib/microwaveprop/radio.ex | 6 ++++-- .../live/user_profile_live.ex | 3 +++ test/microwaveprop/radio_test.exs | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/microwaveprop/radio.ex b/lib/microwaveprop/radio.ex index 58f120f8..68517d55 100644 --- a/lib/microwaveprop/radio.ex +++ b/lib/microwaveprop/radio.ex @@ -129,8 +129,9 @@ defmodule Microwaveprop.Radio do end @doc """ - Returns all contacts where the given callsign appears as either - `station1` or `station2`, newest first. Matching is case-insensitive. + Returns the 100 most recent contacts where the given callsign appears + as either `station1` or `station2`, newest first. Matching is + case-insensitive. """ @spec list_contacts_involving_callsign(String.t() | nil) :: [Contact.t()] def list_contacts_involving_callsign(callsign) when callsign in [nil, ""], do: [] @@ -141,6 +142,7 @@ defmodule Microwaveprop.Radio do Contact |> where([c], fragment("upper(?)", c.station1) == ^upcased or fragment("upper(?)", c.station2) == ^upcased) |> order_by([c], desc: c.qso_timestamp, desc: c.id) + |> limit(100) |> Repo.all() end diff --git a/lib/microwaveprop_web/live/user_profile_live.ex b/lib/microwaveprop_web/live/user_profile_live.ex index b7913c44..7be5f13c 100644 --- a/lib/microwaveprop_web/live/user_profile_live.ex +++ b/lib/microwaveprop_web/live/user_profile_live.ex @@ -159,6 +159,9 @@ defmodule MicrowavepropWeb.UserProfileLive do <%= if @involving == [] do %>

No contacts on file with this callsign yet.

<% else %> +

+ Showing the 100 most recent contacts. +

diff --git a/test/microwaveprop/radio_test.exs b/test/microwaveprop/radio_test.exs index d1f912ef..9dfefae8 100644 --- a/test/microwaveprop/radio_test.exs +++ b/test/microwaveprop/radio_test.exs @@ -552,5 +552,23 @@ defmodule Microwaveprop.RadioTest do assert Radio.list_contacts_involving_callsign("") == [] assert Radio.list_contacts_involving_callsign(nil) == [] end + + test "caps the result at the 100 most recent contacts" do + base = ~U[2020-01-01 00:00:00Z] + + for i <- 1..120 do + create_contact(%{ + station1: "W5ISP", + station2: "K5X#{i}", + qso_timestamp: DateTime.add(base, i * 3600, :second) + }) + end + + result = Radio.list_contacts_involving_callsign("W5ISP") + + assert length(result) == 100 + # The 100 newest by qso_timestamp correspond to i = 21..120; i=120 is newest. + assert hd(result).station2 == "K5X120" + end end end