sqldb+invoices: Optimize invoice fetching when the reference is only a hash

The current sqlc GetInvoice query experiences incremental slowdowns during
the migration of large invoice databases, primarily due to its complex
predicate set. For this specific use case, a streamlined GetInvoiceByHash
function provides a more efficient solution, maintaining near-constant
lookup times even with extensive table sizes.
This commit is contained in:
Andras Banki-Horvath
2024-12-02 19:45:08 +01:00
parent b92f57e0ae
commit 94e2724a34
5 changed files with 91 additions and 20 deletions

View File

@ -54,6 +54,11 @@ WHERE (
GROUP BY i.id
LIMIT 2;
-- name: GetInvoiceByHash :one
SELECT i.*
FROM invoices i
WHERE i.hash = $1;
-- name: GetInvoiceBySetID :many
SELECT i.*
FROM invoices i