-
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?
Conversation
Github tells us which files were modified. If we find that information in the webhook callback, let's not blindly update all posts but instead only update those posts that we were told were modified. This adds a new function to the payload class to get the actual head commit included in the payload. json_decode(json_encode(), true) is used to convert the object to an array - I'm not sure if there is a different way that you would like to use for this (I'm not really a PHP developer - but this works). Signed-off-by: Dirk Hohndel <[email protected]>
I haven't forgotten about this. Will take a look this weekend. Do you have this code in place and running on your site? Wondering how it works in the real world. |
This is NOT ready to pull. |
Sounds good. I await your updates. |
Instead of just looking at the head commit we need to loop over all of the commits that are in the change set that was pushed. This way we will track all of the modified files. Signed-off-by: Dirk Hohndel <[email protected]>
I think this is worth actually taking a look at. |
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.
If you're not that familiar with PHP & PHPUnit, don't worry about the tests; I'm not sure all the failures are related to your code anyway. But if you want to take a shot at updating those, that would be awesome.
@@ -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 ); |
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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
...in which case $commits_array = array()
should go here.
$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 comment
The reason will be displayed to describe this comment to others. Learn more.
Then we could remove this null
check, unless there's a possibility of getting null
from the API.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Because we're still iterating over the tree (see $commit->tree()->blobs()
above), is the savings here primarily from making fewer DB calls?
$update_all = true; | ||
foreach ( $commits_array as $commit_obj ) { | ||
if ( $commit_obj != null ) { | ||
$next_commit = json_decode(json_encode($commit_obj), true); |
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.
We can cast the object to an array with $next_commit = (array) $commit_obj;
instead of the whole JSON thing.
My english is so pool. how to get commits
merge commit to find file of update and new. cache something
max_allowed_packet is 1M by default. so dont overtake it. Make the cache smaller.
|
Based on @lite3 's comments I am in way over my head. |
@dirkhh If you're willing to make the changes suggested, we could resolve the "20 commits issue" by just falling back to the old behavior (get the entire tree), rather than spiking the work you've done already. |
On Tue, Mar 07, 2017 at 04:47:57AM -0800, James DiGioia wrote:
@dirkhh If you're willing to make the changes suggested, we could resolve the "20 commits issue" by just falling back to the old behavior (get the entire tree), rather than spiking the work you've done already.
Sure, I can do that. It will take me a couple of days (work has me crazy
busy this week).
|
Now I am doing a new version, do not cache, do not tree. do not too many commits. |
I have been completely side tracked. I have a hacked version that does what I need, but I'd need to start from scratch to do this right. So if anyone else wants to look, please don't wait for me. |
@mAAdhaTTah I have been complete it. https://github.com/litefeel/writing-on-github/ |
@mAAdhaTTah Replace the tree api with the content api |
@dirkhh @mAAdhaTTah I'm only interested in importing post from Github (not exporting) |
@IeuanWalker We used the Git Data API and build up the new tree based on the current tree, then add a new commit pointing to the new tree. This helps us avoid adding multiple commits for things like the initial site export and batch deletion (which is why we don't use the Content API @litefeel). |
@mAAdhaTTah Thanks but that's mostly for exporting isn't it?, do you something different to import the post from GitHub? All I want to be able to do is add/ update a new post to a repository (not from the web application) and for the web application to pick up the change and add/ update the database. Repository won't need to be updated from the web application. |
No, we use it to read the tree as well. You can also use the Content API, which we used initially. |
@mAAdhaTTah Oh ok. So are you using the push webhook to know when something has been added then the git data api to update/ add the new posts? |
Yeah, basically. |
@mAAdhaTTah cool makes sense thanks :) |
Github tells us which files were modified. If we find that information in the
webhook callback, let's not blindly update all posts but instead only update
those posts that we were told were modified.
This adds a new function to the payload class to get the actual head commit
included in the payload.
json_decode(json_encode(), true) is used to convert the object to an array -
I'm not sure if there is a different way that you would like to use for this
(I'm not really a PHP developer - but this works).
Signed-off-by: Dirk Hohndel [email protected]