Count coalesced waiters as cache hits

d328973 · Gabriel Morell · 2026-08-25 21:15

5 files +13 -2
Message
{commit_body(@commit)}

Files changed

modified apps/room_gtfs/lib/room_gtfs/feed_cache.ex
+13 −2
@@ -161,6 +161,13 @@ defmodule RoomGtfs.FeedCache do
161 161 bump(@fetches)
162 162 end
163 163
164 + # Everyone past the first was coalesced into this one fetch and never
165 + # touched the network, so they count as hits. Without this the counter
166 + # under-reports sharing exactly when sharing is working hardest -- several
167 + # sources asking for one URL at the same instant is the case single flight
168 + # exists for, and it was reading as zero hits.
169 + bump(@hits, length(waiting) - 1)
170 +
164 171 Enum.each(waiting, &GenServer.reply(&1, result))
165 172 {:noreply, %{state | inflight: inflight, refs: refs}}
166 173 end
@@ -225,8 +232,12 @@ defmodule RoomGtfs.FeedCache do
225 232 ArgumentError -> []
226 233 end
227 234
228 − defp bump(pos) do
229 − :ets.update_counter(@table, :__counters__, {pos, 1})
235 + defp bump(pos, by \\ 1)
236 +
237 + defp bump(_pos, by) when by <= 0, do: 0
238 +
239 + defp bump(pos, by) do
240 + :ets.update_counter(@table, :__counters__, {pos, by})
230 241 rescue
231 242 ArgumentError -> 0
232 243 end

Parents: 55e7f46