Menu

I Summed 400,000 Rows on Every Refresh
📰

I Summed 400,000 Rows on Every Refresh

DEV Community: dotnet·Sukhpinder Singh·8 days ago
#nfDkllj7
#devtodotnet#devto#dev#region#counter
Reading 0:00
15s threshold

I had a little dashboard endpoint that summed a sales table by region. Nothing clever: filter the rows, add up the amounts, return a number. It felt instant in dev, so I stopped thinking about it. Then I left the page open on a second monitor. It auto-refreshes every few seconds, and when I tailed the logs I watched the same region total get recomputed over and over, each refresh redoing work whose answer hadn't moved since the last one. The underlying data changes maybe once an hour. I was aggregating 400,000 rows dozens of times a minute to produce a number I'd already produced.

The usual reflex is to reach for IMemoryCache and wrap the computation. That works, but it caches inside the handler, so you still pay for model binding, the handler invocation, and serializing the result every single time. What I actually wanted was for the whole response to come back without my code running at all. That's what output caching does, and it's been sitting in ASP.NET Core since .NET 7.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.