@@ -5,6 +5,7 @@ import { subscriptionSchema } from '../schemas/subscription';
55import { SubscriptionsFetchParams } from '../types' ;
66
77const TABLE = 'subscriptions' ;
8+ const TIMER_LOGGING_LABEL = 'fetch-subscriptions' ;
89
910export async function syncSubscriptions ( postgresClient : PostgresClient , subscriptions : Subscription [ ] ) {
1011 return postgresClient . upsertMany (
@@ -23,25 +24,33 @@ export async function fetchAndSyncSubscriptions(
2324 orbClient : Orb ,
2425 params : SubscriptionsFetchParams
2526) : Promise < number > {
26- const subscriptions = [ ] ;
27+ let numberOfSubscriptions = 0 ;
2728
29+ console . time ( TIMER_LOGGING_LABEL ) ;
2830 let subscriptionsPage = await orbClient . subscriptions . list ( {
2931 limit : params . limit || 100 ,
3032 'created_at[gt]' : params . createdAtGt ,
3133 'created_at[gte]' : params . createdAtGte ,
3234 'created_at[lt]' : params . createdAtLt ,
3335 'created_at[lte]' : params . createdAtLte ,
3436 } ) ;
35- subscriptions . push ( ...subscriptionsPage . data ) ;
37+ console . timeEnd ( TIMER_LOGGING_LABEL ) ;
38+
39+ numberOfSubscriptions += subscriptionsPage . data . length ;
40+
41+ await syncSubscriptions ( postgresClient , subscriptionsPage . data ) ;
3642
3743 while ( subscriptionsPage . hasNextPage ( ) ) {
44+ console . time ( TIMER_LOGGING_LABEL ) ;
3845 subscriptionsPage = await subscriptionsPage . getNextPage ( ) ;
39- subscriptions . push ( ...subscriptionsPage . data ) ;
40- }
46+ console . timeEnd ( TIMER_LOGGING_LABEL ) ;
4147
42- await syncSubscriptions ( postgresClient , subscriptions ) ;
48+ numberOfSubscriptions += subscriptionsPage . data . length ;
49+
50+ await syncSubscriptions ( postgresClient , subscriptionsPage . data ) ;
51+ }
4352
44- return subscriptions . length ;
53+ return numberOfSubscriptions ;
4554}
4655
4756export async function fetchAndSyncSubscription ( postgresClient : PostgresClient , orbClient : Orb , subscriptionId : string ) {
0 commit comments