On Oct 20, 2020, at 1:18 PM, Marcin Romaszewicz <marc...@gmail.com> wrote:
> 
> Go's database layer is generally pretty quick, I use it a lot, but your code 
> immediately sets off my DB alarms, because you are doing queries within the 
> body of another query loop, which means you're opening up lots of 
> connections, which could be slow.
> 
> I'd reorganize as followd.
> 
> - Cache the results of your first query into an array, it's only 6 results.
> - Create two prepared statements, one for each query inside the loop.
> - Loop over your array of 6 results, and execute each prepared statement 
> instead of parsing the query each time.
> 

I would also add that this seems like an excellent candidate for a join, not 
multiple queries, though I admit to not having looked *terribly* closely at the 
query structure.  That should cut down on overhead and complexity a lot.


- Dave


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/79681751-275B-4FD4-A9E8-F69ABC6C0F5B%40gmail.com.

Attachment: signature.asc
Description: Message signed with OpenPGP

Reply via email to