Fix: skip first query when fromPaidTimestamp is 0
This commit is contained in:
parent
9e21c515d6
commit
d6b6ee61d1
1 changed files with 19 additions and 15 deletions
|
|
@ -74,8 +74,10 @@ export default class {
|
|||
}
|
||||
|
||||
async GetUserInvoicesFlaggedAsPaid(userSerialId: number, fromIndex: number, fromPaidTimestamp: number, take = 50, txId?: string): Promise<UserReceivingInvoice[]> {
|
||||
let items: UserReceivingInvoice[] = [];
|
||||
if (fromPaidTimestamp > 0) {
|
||||
// First fetch same paid_at_unix, higher serial_id
|
||||
let items = await this.dbs.Find<UserReceivingInvoice>('UserReceivingInvoice', {
|
||||
const firstBatch = await this.dbs.Find<UserReceivingInvoice>('UserReceivingInvoice', {
|
||||
where: {
|
||||
user: { serial_id: userSerialId },
|
||||
paid_at_unix: And(MoreThan(0), Equal(fromPaidTimestamp)),
|
||||
|
|
@ -86,12 +88,14 @@ export default class {
|
|||
serial_id: 'ASC'
|
||||
},
|
||||
take
|
||||
}, txId)
|
||||
}, txId);
|
||||
items.push(...firstBatch);
|
||||
}
|
||||
|
||||
const needMore = take - items.length
|
||||
// If need more, fetch higher paid_at_unix
|
||||
if (needMore > 0) {
|
||||
const more = await this.dbs.Find<UserReceivingInvoice>('UserReceivingInvoice', {
|
||||
const secondBatch = await this.dbs.Find<UserReceivingInvoice>('UserReceivingInvoice', {
|
||||
where: {
|
||||
user: { serial_id: userSerialId },
|
||||
paid_at_unix: And(MoreThan(0), MoreThan(fromPaidTimestamp)),
|
||||
|
|
@ -102,7 +106,7 @@ export default class {
|
|||
},
|
||||
take: needMore
|
||||
}, txId)
|
||||
items.push(...more)
|
||||
items.push(...secondBatch)
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue