Menu

Four Million Checks for Two Million Orders
📰

Four Million Checks for Two Million Orders

DEV Community: dotnet·Sukhpinder Singh·17 days ago
#Wx0xAnGq
#devtodotnet#devto#dev#count#once
Reading 0:00
15s threshold

A reporting endpoint got slow enough that someone pinged me about it, and the method at the center of it looked completely harmless. It took a sequence of orders, logged how many were billable, then added up their amounts. Three lines of real work. The kind of code you skim past in review because there's nothing to argue with.

public static decimal Summarize ( IEnumerable < Order > billable ) { int n = billable . Count (); decimal total = 0m ; foreach ( var o in billable ) total += o . Amount ;

log . Information ( "{Count} billable orders" , n ); return total ; }

Enter fullscreen mode

Exit fullscreen mode

The part I slid right past was the parameter type. IEnumerable<Order> . And here's what the caller was handing in:

Summarize ( orders . Where ( IsBillable ));

Enter fullscreen mode

Exit fullscreen mode

A Where doesn't filter anything when you call it. It hands back a little object that promises to filter later, once somebody walks it.…

Continue reading — create a free account

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