-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only update posts that are marked as modified #167
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,8 @@ public function payload( WordPress_GitHub_Sync_Payload $payload ) { | |
*/ | ||
$error = false; | ||
|
||
$result = $this->commit( $this->app->api()->fetch()->commit( $payload->get_commit_id() ) ); | ||
$commits = $payload->get_commits(); | ||
$result = $this->commit( $this->app->api()->fetch()->commit( $payload->get_commit_id() ), $commits ); | ||
|
||
if ( is_wp_error( $result ) ) { | ||
$error = $result; | ||
|
@@ -76,7 +77,7 @@ public function payload( WordPress_GitHub_Sync_Payload $payload ) { | |
* @return string|WP_Error | ||
*/ | ||
public function master() { | ||
return $this->commit( $this->app->api()->fetch()->master() ); | ||
return $this->commit( $this->app->api()->fetch()->master(), null ); | ||
} | ||
|
||
/** | ||
|
@@ -86,7 +87,20 @@ public function master() { | |
* | ||
* @return string|WP_Error | ||
*/ | ||
protected function commit( $commit ) { | ||
protected function commit( $commit , $commits_array) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...in which case |
||
$head_commit = array(); | ||
$mod_files = array(); | ||
$update_all = true; | ||
foreach ( $commits_array as $commit_obj ) { | ||
if ( $commit_obj != null ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then we could remove this |
||
$next_commit = json_decode(json_encode($commit_obj), true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can cast the object to an array with |
||
if ( array_key_exists( 'modified', $next_commit ) ) { | ||
$mod_files = array_merge($mod_files, $next_commit['modified']); | ||
$update_all = false; | ||
} | ||
} | ||
} | ||
|
||
if ( is_wp_error( $commit ) ) { | ||
return $commit; | ||
} | ||
|
@@ -103,10 +117,20 @@ protected function commit( $commit ) { | |
continue; | ||
} | ||
|
||
$posts[] = $post = $this->blob_to_post( $blob ); | ||
$post = $this->blob_to_post( $blob ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we're still iterating over the tree (see |
||
|
||
$found = $update_all; | ||
foreach ( $mod_files as $modified_file ) { | ||
if ($blob->path() == $modified_file) { | ||
$found = true; | ||
} | ||
} | ||
|
||
if ( $post->is_new() ) { | ||
$posts[] = $post; | ||
$new[] = $post; | ||
} elseif ( $found ) { | ||
$posts[] = $post; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing in
null
here, we should not pass in anything and update the default value for this method.