-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Update indexer:reset
to call $indexer->invalidate()
#34582
Update indexer:reset
to call $indexer->invalidate()
#34582
Conversation
I was recently debugging something that was invalidating the indexers. I added some logging using a before plugin on the `invalidate` function https://github.com/magento/magento2/blob/227cf9229152ed4332c607796cf476055ef9ec4f/app/code/Magento/Indexer/Model/Indexer.php#L345-L355 But this use case isn't covered. It seems to me that this command should just call the function that invalidates the indexer rather than repeating the work itself.
Hi @convenient. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review. For more details, review the Magento Contributor Guide documentation. 🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
$indexer->invalidate()
$indexer->invalidate()
indexer:reset
to call $indexer->invalidate()
indexer:reset
to call $indexer->invalidate()
indexer:reset
to call $indexer->invalidate()
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
@magento run Functional Tests CE, Functional Tests EE |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
indexer:reset
to call $indexer->invalidate()
indexer:reset
to call $indexer->invalidate()
@magento run Functional Tests B2B |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
Hi @andrewbess, thank you for the review.
|
Thanks for your collaboration and contribution @convenient and @andrewbess .
Expected before PR Changes : Observation: Not found any logs after PR changes made. Please lets know if we have to modify anything in the above execution steps |
@engcom-Delta I can see your class isn't being constructed with the logger property? so I would expect a PHP fatal error to be logged? However if no fatal error is occurring it suggests you dont have the plugin hooked in correctly? If you're adding a plugin you'll need to clear the relevant generated directories and caches This is what I have running in production... diff --git a/src/Plugin/Indexer.php b/src/Plugin/Indexer.php
new file mode 100644
index 0000000..9aa35d1
--- /dev/null
+++ b/src/Plugin/Indexer.php
@@ -0,0 +1,32 @@
+<?php
+namespace Ampersand\MviewIndexerLogger\Plugin;
+
+class Indexer
+{
+ /** @var \Psr\Log\LoggerInterface */
+ private $logger;
+
+ /**
+ * Action constructor.
+ * @param \Psr\Log\LoggerInterface $logger
+ */
+ public function __construct(
+ \Psr\Log\LoggerInterface $logger
+ ) {
+ $this->logger = $logger;
+ }
+
+ /**
+ * @param \Magento\Framework\Indexer\IndexerInterface $subject
+ */
+ public function beforeInvalidate(\Magento\Framework\Indexer\IndexerInterface $subject)
+ {
+ $this->logger->info(
+ "Invalidating index",
+ [
+ 'indexer_id' => $subject->getId(),
+ 'trace' => str_replace(PHP_EOL, '|', (new \Exception())->getTraceAsString())
+ ]
+ );
+ }
+}
diff --git a/src/etc/di.xml b/src/etc/di.xml
index 8867f14..4d07f02 100644
--- a/src/etc/di.xml
+++ b/src/etc/di.xml
@@ -4,4 +4,7 @@
<type name="Magento\Framework\Mview\ActionInterface">
<plugin name="Ampersand\MviewIndexerLogger\Plugin\Action" type="Ampersand\MviewIndexerLogger\Plugin\Action"/>
</type>
+ <type name="Magento\Framework\Indexer\IndexerInterface">
+ <plugin name="log-invalidate-indexer-trace" type="Ampersand\MviewIndexerLogger\Plugin\Indexer"/>
+ </type>
</config> |
Also @engcom-Delta the main thing that needs tested is that calling The plugin was just a bit of background why we don't want to have duplicated code, explaining my use case, it's just gravy. |
@magento create issue |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
I was recently debugging something that was invalidating the indexers.
I added some logging using a before plugin on the
invalidate
functionBut this use case isn't caught in my logs.
It seems to me that this command should just call the function that invalidates the indexer rather than repeating the work itself. I'm sorting out my own logging / debugging internally, but this seems sensible to fix here.
magento2/app/code/Magento/Indexer/Model/Indexer.php
Lines 345 to 355 in 227cf92
Manual testing scenarios (*)
indexer:reset
and see the indexer was invalidatedContribution checklist (*)
Resolved issues:
indexer:reset
to call$indexer->invalidate()
#34988: Updateindexer:reset
to call$indexer->invalidate()