Skip to content

Commit fdd6c17

Browse files
committed
Add recursive URL discovery during direct deploys
1 parent 7acaf2a commit fdd6c17

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/DirectDeployer.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,27 @@ public function __construct() {
3838
}
3939

4040
public function deploy() : void {
41+
global $wpdb;
42+
43+
$queue_table = CrawlQueue::getTableName();
44+
$last_now = $wpdb->get_var( 'SELECT NOW()' );
45+
4146
$detected = URLDetector::detectURLsIter();
4247
$added = CrawlQueue::withPathsIter( $detected );
4348
$this->deployPaths( $added );
49+
50+
while ( true ) {
51+
$sql = $wpdb->prepare( "SELECT COUNT(*) FROM $queue_table WHERE detected_at > %s", $last_now );
52+
$new_ct = intval( $wpdb->get_var( $sql ) );
53+
if ( 0 === $new_ct ) {
54+
break;
55+
}
56+
WsLog::l ( "Found $new_ct new URLs during crawling." );
57+
$detected = CrawlQueue::getPathsIter( $last_now );
58+
$last_now = $wpdb->get_var( 'SELECT NOW()' );
59+
$added = CrawlQueue::withPathsIter( $detected );
60+
$this->deployPaths( $added, false );
61+
}
4462
}
4563

4664
public function deployComplete() : void {
@@ -51,9 +69,11 @@ public function deployComplete() : void {
5169
do_action( 'wp2static_post_direct_deploy_trigger', $this );
5270
}
5371

54-
public function deployPaths( \Iterator $paths ) : void {
72+
public function deployPaths( \Iterator $paths, bool $remove_404s = true ) : void {
5573
$crawled = $this->crawler->crawlIter( $paths );
56-
$crawled = CrawlCache::remove404s( $crawled );
74+
if ( $remove_404s ) {
75+
$crawled = CrawlCache::remove404s( $crawled );
76+
}
5777

5878
if ( $this->use_crawl_cache ) {
5979
$crawled = CrawlCache::addPathsIter( $crawled );

0 commit comments

Comments
 (0)