@@ -45,35 +45,41 @@ graceful.listen();
4545 // get list of all suspended domains
4646 // and recently blocked emails to exclude
4747 const now = new Date ( ) ;
48- let [ suspendedDomainIds , recentlyBlockedIds ] = await Promise . all ( [
49- Domains . aggregate ( [
50- { $match : { is_smtp_suspended : true } } ,
51- { $group : { _id : '$_id' } }
52- ] )
53- . allowDiskUse ( true )
54- . exec ( ) ,
55- Emails . aggregate ( [
56- {
57- $match : {
58- updated_at : {
59- $gte : dayjs ( ) . subtract ( 1 , 'hour' ) . toDate ( ) ,
60- $lte : now
61- } ,
62- has_blocked_hashes : true ,
63- blocked_hashes : {
64- $in : getBlockedHashes ( env . SMTP_HOST )
65- }
48+ const suspendedDomainIds = [ ] ;
49+ const recentlyBlockedIds = [ ] ;
50+
51+ await Promise . all ( [
52+ ( async ( ) => {
53+ for await ( const domain of Domains . find ( {
54+ is_smtp_suspended : true
55+ } )
56+ . select ( '_id' )
57+ . lean ( )
58+ . cursor ( )
59+ . addCursorFlag ( 'noCursorTimeout' , true ) ) {
60+ suspendedDomainIds . push ( domain . _id ) ;
61+ }
62+ } ) ( ) ,
63+ ( async ( ) => {
64+ for await ( const email of Emails . find ( {
65+ updated_at : {
66+ $gte : dayjs ( ) . subtract ( 1 , 'hour' ) . toDate ( ) ,
67+ $lte : now
68+ } ,
69+ has_blocked_hashes : true ,
70+ blocked_hashes : {
71+ $in : getBlockedHashes ( env . SMTP_HOST )
6672 }
67- } ,
68- { $group : { _id : '$_id' } }
69- ] )
70- . allowDiskUse ( true )
71- . exec ( )
73+ } )
74+ . select ( '_id' )
75+ . lean ( )
76+ . cursor ( )
77+ . addCursorFlag ( 'noCursorTimeout' , true ) ) {
78+ recentlyBlockedIds . push ( email . _id ) ;
79+ }
80+ } ) ( )
7281 ] ) ;
7382
74- suspendedDomainIds = suspendedDomainIds . map ( ( v ) => v . _id ) ;
75- recentlyBlockedIds = recentlyBlockedIds . map ( ( v ) => v . _id ) ;
76-
7783 logger . info ( '%d suspended domain ids' , suspendedDomainIds . length ) ;
7884
7985 logger . info ( '%d recently blocked ids' , recentlyBlockedIds . length ) ;
0 commit comments