File tree Expand file tree Collapse file tree 1 file changed +25
-15
lines changed
Expand file tree Collapse file tree 1 file changed +25
-15
lines changed Original file line number Diff line number Diff line change @@ -93,25 +93,35 @@ export default event({
9393 ) {
9494 console . log ( 'Handling new thread in Jobs channel' ) ;
9595 try {
96+ let allJobPosts = [ ] ;
97+
9698 const threadCacheA =
9799 await message . channel . parent . threads . fetchActive ( false ) ;
98- const threadCacheB =
99- await message . channel . parent . threads . fetchArchived (
100- {
101- fetchAll : true ,
102- limit : 100 ,
103- } ,
104- false ,
105- ) ;
100+ allJobPosts = [ ...threadCacheA . threads . values ( ) ] ;
106101
107- console . log (
108- `Fetched ${ threadCacheA . threads . size } active and ${ threadCacheB . threads . size } archived threads. hasMore is ${ threadCacheB . hasMore } ` ,
109- ) ;
102+ let hasMore = true ;
103+ let before ;
104+
105+ while ( hasMore ) {
106+ const threadCacheB =
107+ await message . channel . parent . threads . fetchArchived (
108+ {
109+ fetchAll : true ,
110+ limit : 100 ,
111+ before,
112+ } ,
113+ false ,
114+ ) ;
115+ hasMore = threadCacheB . hasMore ;
116+ before = threadCacheB . threads . last ( ) ;
117+ allJobPosts = [
118+ ...allJobPosts ,
119+ ...threadCacheB . threads . values ( ) ,
120+ ] ;
121+ }
122+
123+ console . log ( `Fetched ${ allJobPosts . length } threads` ) ;
110124
111- const allJobPosts = [
112- ...threadCacheA . threads . values ( ) ,
113- ...threadCacheB . threads . values ( ) ,
114- ] ;
115125 const userThreads = allJobPosts
116126 . filter ( ( thread ) => thread . ownerId === message . author . id )
117127 . filter ( ( thread ) => thread . id !== message . id ) ;
You can’t perform that action at this time.
0 commit comments