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.
This commit is contained in:
parent
6515f84079
commit
7463cdcc7b
3 changed files with 25 additions and 2 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -159,6 +159,9 @@ defmodule MicrowavepropWeb.UserProfileLive do
|
|||
<%= if @involving == [] do %>
|
||||
<p class="text-sm opacity-70">No contacts on file with this callsign yet.</p>
|
||||
<% else %>
|
||||
<p :if={length(@involving) == 100} class="text-xs opacity-60">
|
||||
Showing the 100 most recent contacts.
|
||||
</p>
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table table-zebra table-sm">
|
||||
<thead>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue