@@ -91,15 +91,19 @@ export default class TransferDbRepository implements TransferRepository {
9191 }
9292
9393 if ( after ) {
94- queryParams . push ( after ) ;
94+ const [ creationTime , id ] = after . split ( ':' ) ;
95+ queryParams . push ( creationTime ) ;
9596 const op = operator ( queryParams . length ) ;
96- conditions += `\n${ op } transfers.id < $${ queryParams . length } ` ;
97+ queryParams . push ( id ) ;
98+ conditions += `\n${ op } (t.creationtime, t.id) < ($${ queryParams . length - 1 } , $${ queryParams . length } )` ;
9799 }
98100
99101 if ( before ) {
100- queryParams . push ( before ) ;
102+ const [ creationTime , id ] = before . split ( ':' ) ;
103+ queryParams . push ( creationTime ) ;
101104 const op = operator ( queryParams . length ) ;
102- conditions += `\n${ op } transfers.id > $${ queryParams . length } ` ;
105+ queryParams . push ( id ) ;
106+ conditions += `\n${ op } (t.creationtime, t.id) > ($${ queryParams . length - 1 } , $${ queryParams . length } )` ;
103107 }
104108
105109 if ( chainId ) {
@@ -155,7 +159,7 @@ export default class TransferDbRepository implements TransferRepository {
155159 join "Transfers" transfers on transfers."transactionId" = t.id
156160 left join "TransactionDetails" td on t.id = td."transactionId"
157161 ${ conditions }
158- ORDER BY transfers.id ${ order }
162+ ORDER BY t."creationtime" ${ order } , transfers.id ${ order }
159163 LIMIT $1
160164 ` ;
161165 } else if ( requestKey ) {
@@ -185,47 +189,11 @@ export default class TransferDbRepository implements TransferRepository {
185189 join "Transfers" transfers on transfers."transactionId" = t.id
186190 left join "TransactionDetails" td on t.id = td."transactionId"
187191 ${ conditions }
188- ORDER BY transfers.id ${ order }
189- LIMIT $1
190- ` ;
191- } else if ( accountName ) {
192- query = `
193- WITH filtered_transfers AS (
194- SELECT id, amount, "transactionId", "from_acct", "to_acct", modulename, modulehash, requestkey, "orderIndex"
195- FROM "Transfers" transfers
196- ${ conditions }
197- ORDER BY transfers.id ${ order }
198- LIMIT ALL
199- )
200- select transfers.id as id,
201- transfers.amount as "transferAmount",
202- t."chainId" as "chainId",
203- t."creationtime" as "creationTime",
204- t.id as "transactionId",
205- b.height as "height",
206- b.hash as "blockHash",
207- transfers."from_acct" as "senderAccount",
208- transfers."to_acct" as "receiverAccount",
209- transfers.modulename as "moduleName",
210- transfers.modulehash as "moduleHash",
211- transfers.requestkey as "requestKey",
212- transfers."orderIndex" as "orderIndex",
213- td.pactid as "pactId"
214- from filtered_transfers transfers
215- join "Transactions" t on t.id = transfers."transactionId"
216- join "Blocks" b on b."id" = t."blockId"
217- left join "TransactionDetails" td on t.id = td."transactionId"
192+ ORDER BY t."creationtime" ${ order } , transfers.id ${ order }
218193 LIMIT $1
219194 ` ;
220195 } else {
221196 query = `
222- WITH filtered_transfers AS (
223- SELECT id, amount, "transactionId", "from_acct", "to_acct", modulename, modulehash, requestkey, "orderIndex"
224- FROM "Transfers" transfers
225- ${ conditions }
226- ORDER BY transfers.id ${ order }
227- LIMIT $1
228- )
229197 select transfers.id as id,
230198 transfers.amount as "transferAmount",
231199 t."chainId" as "chainId",
@@ -240,17 +208,20 @@ export default class TransferDbRepository implements TransferRepository {
240208 transfers.requestkey as "requestKey",
241209 transfers."orderIndex" as "orderIndex",
242210 td.pactid as "pactId"
243- from filtered_transfers transfers
211+ from "Transfers" transfers
244212 join "Transactions" t on t.id = transfers."transactionId"
245213 join "Blocks" b on b."id" = t."blockId"
246214 left join "TransactionDetails" td on t.id = td."transactionId"
215+ ${ conditions }
216+ ORDER BY t."creationtime" ${ order } , transfers.id ${ order }
217+ LIMIT $1
247218 ` ;
248219 }
249220
250221 const { rows } = await rootPgPool . query ( query , queryParams ) ;
251222
252223 const edges = rows . map ( row => ( {
253- cursor : row . id . toString ( ) ,
224+ cursor : ` ${ row . creationTime . toString ( ) } : ${ row . id . toString ( ) } ` ,
254225 node : transferSchemaValidator . validate ( row ) ,
255226 } ) ) ;
256227
0 commit comments