-
Notifications
You must be signed in to change notification settings - Fork 73
Allow skipping non Algolia entities in commands #109
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
Allow skipping non Algolia entities in commands #109
Conversation
|
Hi @gruberro, Thanks for your contribution to the project! You're right the behavior seems a bit odd. I'm wondering if we really need an option for that. I assume that a fairly large application, not all entities get indexed anyway. What do you think? |
|
My intention to add it by option was to have the change backward compatible. Otherwise the default behavior would change. But to be honest having the commands skipping all non Algolia entities by default is somehow expected 😄 . Your assumption is correct. In our applications only the business relevant entities are indexed! |
|
I understand why you want to keep backward compat', it's very important and we should keep it as much as possible. Thanks for caring. I'm trying to think about the drawbacks of modifying this behavior. Today, if you have a non-Algolia entity you will get an exception, so all entities that was supposed to be indexed after are skipped. I feel like it adds some complexity and I can't think about a situation where you want/need an exception. I came up with this poc to carry on the discussion: 7e72a38 |
|
You're absolutely right, I can't think of another situation you've not listed yet, so it might be safe to make skipping default as well. Can change this if you're ok with it! |
|
Agree with @julienbourdeau I don't see any issue skipping them as long as you put a clear message that it was skipped |
|
Hi @gruberro, So everyone agrees! Can you rework your pull request? Then I'll be happy to merge it! |
50d2872 to
202738d
Compare
|
@julienbourdeau did the small refactoring as we discussed before! |
julienbourdeau
left a comment
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.
Thanks again for your contribution! I left a few comments on your PR.
I cannot get the test to pass, can you have a look please?
| { | ||
| $reIndexer = $this->getContainer()->get('algolia.indexer')->getManualIndexer($this->getObjectManager()); | ||
|
|
||
| return $reIndexer->reIndex($className, [ |
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.
Why did you remove the return here?
|
|
||
| $nIndexed = 0; | ||
| foreach ($toReindex as $className) { | ||
| $nIndexed += $this->reIndex($className, $batchSize, $safe); |
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.
Are you sure $this->reIndex() always returned 1? 🤔
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.
Ah damn... is fixed!
|
|
||
| public function testClearWillFailWithNonAlgoliaMappedEntity() | ||
| { | ||
| $this->setExpectedException( |
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.
Please use expectException() since this method has been removed in PHPUnit 6.
202738d to
d3e5fd2
Compare
|
@julienbourdeau took a look and fixed the failing tests cases... at least it's stable with my local setup |
| foreach ($toClear as $className) { | ||
| try { | ||
| $this->clear($className); | ||
| $nCleared++; |
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.
Same here, I'm not sure about this. I'd rather keep the return statement in clear() and add the result to $nCleared.
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 this particular case this won't make sense IMO as the underlaying indexer is not returning the number of affected documents (void) (https://github.com/algolia/AlgoliaSearchBundle/blob/master/Indexer/ManualIndexer.php#L166-L179). So counting the number of entity types being cleared is the only information that can be gathered here.
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.
Indeed, Thanks!
|
Hi @gruberro, Thanks for you edits. Can you have a look at my latest comment? Also, it seems like you merge master into your branch. Would you mind cleaning your branch? If you're not very familiar with this I would recommend you to create a new one, cherry-pick your commit and push it to the same remote branch. Make sure that your git configuration is set to rebase on pull and not merge. Thanks again for your contribution! |
|
@julienbourdeau oh damn... seems it was way too late yesterday night. I'll rebase the PR.. sry 😟 |
a7a7b26 to
dcd16f4
Compare
| $input = new ArrayInput($options); | ||
|
|
||
| $this->command->run($input, new ConsoleOutput()); | ||
| $this->command->run($input, new NullOutput()); |
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.
Travis fails and I get the same result locally. I manage to get the tests passing but using ConsoleOutput like it was before.
Why did you change this to NullOutput?
After that I believe we'll be ready to merge! 🎉
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.
I've changed it to NullOutput to avoid output to the console during test execution which may cause risky tests (at least if configured). But if it's breaking the build I'll change for sure (unfortunately it's not breaking the build on my machine 😟)! WDYT of using the BufferedOutput which could then also be used to check if some excepted output has been written?
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.
I understand, I wish we could get rid of the "30 entities indexed" too. I tried on my local environnement, it didn't work so I expect problems with Travis as well.
Feel free to open a new pull request dedicated to that :)
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.
Reverted my changes to ConsoleOutput as suggested by you. Will try to investigate your errors in a new pull request. Are your local errors the same as the one's on Travis? (No output has been received in the last 10m0s, this potentially indicates a stalled build or something wrong with the build itself.) Just to be sure to search for the same thingies 😄.
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.
I don't think it's the same, I'm using Homestead and I think pretty much with everything by default.
When invoking the clear or reindex command for all known entities the command will fail if at least one entity is not Algolia mapped. This is incosistent regarding the settings command and makes it difficult in automation processes. With this change the commands will no longer trigger an error but skip non Algolia entities. An informational output will be shown.
dcd16f4 to
8de0880
Compare
|
@julienbourdeau can we get this merged please? |
|
Yes, definitely. I'm looking into travis right now. |
|
@julienbourdeau any luck with travis? |
|
@julienbourdeau really looking forward to 3.0, but is there any chance to bring this into 2.x? |
|
Yes, I'll release a new version of 2.0 with most of the open PR. They make a lot of sense and I don't want to waste the work done here 👍 |
When invoking the clear or reindex command for all known entities the command will fail if at least one entity is not Algolia mapped. This is inkonsistent regarding the settings command and makes it
difficult in automation processes.
By adding a new optional command line settings this kind of error can be skipped. By default the command behavior is not changing (BC).