@@ -85,17 +85,21 @@ public function init() {
8585 * @return bool
8686 */
8787 public function should_add_task () {
88- // Detect if there are more than 10 PDF files.
89- $ query = new \WP_Query (
90- [
91- 'post_type ' => 'attachment ' ,
92- 'post_mime_type ' => 'application/pdf ' ,
93- 'post_status ' => 'publish ' ,
94- 'posts_per_page ' => static ::MIN_PDF_FILES + 1 , // We want to get at least 11 PDF files to be sure we have enough.
95- 'fields ' => 'ids ' ,
96- ]
97- );
98- $ pdf_files_count = $ query ->found_posts ;
88+ $ pdf_files_count = \progress_planner ()->get_utils__cache ()->get ( 'pdf_files_count ' );
89+ if ( false === $ pdf_files_count ) {
90+ // Detect if there are more than 10 PDF files.
91+ $ query = new \WP_Query (
92+ [
93+ 'post_type ' => 'attachment ' ,
94+ 'post_mime_type ' => 'application/pdf ' ,
95+ 'post_status ' => 'publish ' ,
96+ 'posts_per_page ' => static ::MIN_PDF_FILES + 1 , // We want to get at least 11 PDF files to be sure we have enough.
97+ 'fields ' => 'ids ' ,
98+ ]
99+ );
100+ $ pdf_files_count = $ query ->found_posts ;
101+ \progress_planner ()->get_utils__cache ()->set ( 'pdf_count ' , $ pdf_files_count , DAY_IN_SECONDS );
102+ }
99103
100104 return static ::MIN_PDF_FILES < $ pdf_files_count ;
101105 }
0 commit comments