sqldb+invoices: fix ordering bug in FilterInvoices
Previously if the `reverse` named arg was unset (value of NULL), then
SQL would order by NULL instead of ID causing undifined ordering of the
returned rows. To fix that we check for NULL and also make sure to set
the `reverse` arg in the code explicitly as it in the generated code it
is an `interface{}` instead of `bool`.
This commit is contained in:
3 files changed
+13
-10
No files matched your search
+11
-8
@@ -624,6 +624,7 @@ func (i *SQLStore) FetchPendingInvoices(ctx context.Context) (
|
|||||||
PendingOnly: true,
|
PendingOnly: true,
|
||||||
NumOffset: int32(offset),
|
NumOffset: int32(offset),
|
||||||
NumLimit: int32(limit),
|
NumLimit: int32(limit),
|
||||||
|
Reverse: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := db.FilterInvoices(ctx, params)
|
rows, err := db.FilterInvoices(ctx, params)
|
||||||
@@ -683,6 +684,7 @@ func (i *SQLStore) InvoicesSettledSince(ctx context.Context, idx uint64) (
|
|||||||
SettleIndexGet: sqldb.SQLInt64(settleIdx + 1),
|
SettleIndexGet: sqldb.SQLInt64(settleIdx + 1),
|
||||||
NumLimit: int32(limit),
|
NumLimit: int32(limit),
|
||||||
NumOffset: int32(offset),
|
NumOffset: int32(offset),
|
||||||
|
Reverse: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := db.FilterInvoices(ctx, params)
|
rows, err := db.FilterInvoices(ctx, params)
|
||||||
@@ -798,6 +800,7 @@ func (i *SQLStore) InvoicesAddedSince(ctx context.Context, idx uint64) (
|
|||||||
AddIndexGet: sqldb.SQLInt64(addIdx + 1),
|
AddIndexGet: sqldb.SQLInt64(addIdx + 1),
|
||||||
NumLimit: int32(limit),
|
NumLimit: int32(limit),
|
||||||
NumOffset: int32(offset),
|
NumOffset: int32(offset),
|
||||||
|
Reverse: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := db.FilterInvoices(ctx, params)
|
rows, err := db.FilterInvoices(ctx, params)
|
||||||
@@ -857,14 +860,6 @@ func (i *SQLStore) QueryInvoices(ctx context.Context,
|
|||||||
PendingOnly: q.PendingOnly,
|
PendingOnly: q.PendingOnly,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !q.Reversed {
|
|
||||||
// The invoice with index offset id must not be
|
|
||||||
// included in the results.
|
|
||||||
params.AddIndexGet = sqldb.SQLInt64(
|
|
||||||
q.IndexOffset + uint64(offset) + 1,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if q.Reversed {
|
if q.Reversed {
|
||||||
idx := int32(q.IndexOffset)
|
idx := int32(q.IndexOffset)
|
||||||
|
|
||||||
@@ -883,6 +878,14 @@ func (i *SQLStore) QueryInvoices(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
params.Reverse = true
|
params.Reverse = true
|
||||||
|
} else {
|
||||||
|
// The invoice with index offset id must not be
|
||||||
|
// included in the results.
|
||||||
|
params.AddIndexGet = sqldb.SQLInt64(
|
||||||
|
q.IndexOffset + uint64(offset) + 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
params.Reverse = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if q.CreationDateStart != 0 {
|
if q.CreationDateStart != 0 {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ WHERE (
|
|||||||
)
|
)
|
||||||
ORDER BY
|
ORDER BY
|
||||||
CASE
|
CASE
|
||||||
WHEN $9 = FALSE THEN id
|
WHEN $9 = FALSE OR $9 IS NULL THEN id
|
||||||
ELSE NULL
|
ELSE NULL
|
||||||
END ASC,
|
END ASC,
|
||||||
CASE
|
CASE
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ WHERE (
|
|||||||
)
|
)
|
||||||
ORDER BY
|
ORDER BY
|
||||||
CASE
|
CASE
|
||||||
WHEN sqlc.narg('reverse') = FALSE THEN id
|
WHEN sqlc.narg('reverse') = FALSE OR sqlc.narg('reverse') IS NULL THEN id
|
||||||
ELSE NULL
|
ELSE NULL
|
||||||
END ASC,
|
END ASC,
|
||||||
CASE
|
CASE
|
||||||
|
|||||||
Reference in new issue
Block a user