doublesecretagency / craft-viewcount

View Count plugin for Craft CMS
Other
6 stars 4 forks source link

Lots of warnings flagged in Craft's web logs #27

Closed icreatestuff closed 1 year ago

icreatestuff commented 1 year ago

We are seeing 1,000s of repeated errors like the one below in our daily web log files

2023-09-07 09:55:14 [web.WARNING] [craft\elements\db\ElementQuery::prepare] Element query executed before Craft is fully initialized. Stack trace: 
    #0 /home/our-website.test/vendor/yiisoft/yii2/db/QueryBuilder.php(227): craft\elements\db\ElementQuery->prepare() 
    #1 /home/our-website.test/vendor/yiisoft/yii2/db/Query.php(157): yii\db\QueryBuilder->build() 
    #2 /home/our-website.test/vendor/yiisoft/yii2/db/Query.php(287): yii\db\Query->createCommand() 
    #3 /home/our-website.test/vendor/craftcms/cms/src/db/Query.php(275): yii\db\Query->one() 
    #4 /home/our-website.test/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1604): craft\db\Query->one() 
    #5 /home/our-website.test/vendor/craftcms/cms/src/elements/User.php(545): craft\elements\db\ElementQuery->one() 
    #6 /home/our-website.test/vendor/yiisoft/yii2/web/User.php(698): craft\elements\User::findIdentity() 
    #7 /home/our-website.test/vendor/craftcms/cms/src/web/User.php(500): yii\web\User->renewAuthStatus() 
    #8 /home/our-website.test/vendor/yiisoft/yii2/web/User.php(199): craft\web\User->renewAuthStatus() 
    #9 /home/our-website.test/vendor/doublesecretagency/craft-viewcount/src/ViewCount.php(69): yii\web\User->getIdentity() 
    #10 /home/our-website.test/vendor/yiisoft/yii2/base/BaseObject.php(109): doublesecretagency\viewcount\ViewCount->init() 
    #11 /home/our-website.test/vendor/yiisoft/yii2/base/Module.php(161): yii\base\BaseObject->__construct() 
    #12 /home/our-website.test/vendor/craftcms/cms/src/base/Plugin.php(122): yii\base\Module->__construct() 
    #13 craft\base\Plugin->__construct() 
    #14 /home/our-website.test/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs() 
    #15 /home/our-website.test/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build() 
    #16 /home/our-website.test/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get() 
    #17 /home/our-website.test/vendor/craftcms/cms/src/Craft.php(54): yii\BaseYii::createObject() 
    #18 /home/our-website.test/vendor/craftcms/cms/src/services/Plugins.php(943): Craft::createObject() 
    #19 /home/our-website.test/vendor/craftcms/cms/src/services/Plugins.php(228): craft\services\Plugins->createPlugin() 
    #20 /home/our-website.test/vendor/craftcms/cms/src/base/ApplicationTrait.php(1595): craft\services\Plugins->loadPlugins() 
    #21 /home/our-website.test/vendor/craftcms/cms/src/web/Application.php(108): craft\web\Application->_postInit() 
    #22 /home/our-website.test/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\web\Application->init() 
    #23 /home/our-website.test/vendor/yiisoft/yii2/base/Application.php(204): yii\base\BaseObject->__construct() 
    #24 yii\base\Application->__construct() 
    #25 /home/our-website.test/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs() 
    #26 /home/our-website.test/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build() 
    #27 /home/our-website.test/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get() 
    #28 /home/our-website.test/vendor/craftcms/cms/src/Craft.php(54): yii\BaseYii::createObject() 
    #29 /home/our-website.test/vendor/craftcms/cms/bootstrap/bootstrap.php(256): Craft::createObject() 
    #30 /home/our-website.test/vendor/craftcms/cms/bootstrap/web.php(40): require() 
    #31 /home/our-website.test/web/index.php(11): require() {"memory":3114784} 

Is there anything that can be done about when the Craft::$app->user->getIdentity() is run to prevent this? Thanks

Craft: Pro 4.5.3 View Count: 1.2.1

lindseydiloreto commented 1 year ago

Good news, a similar PR was submitted for the Upvote plugin, which has a similar underlying architecture. So I roughly copied the solution from there, and I think it resolved the issue.

Would you mind testing this before I push a formal release?

"doublesecretagency/craft-viewcount": "dev-v1-dev"
icreatestuff commented 1 year ago

Hi @lindseydiloreto yes that looks to have done the trick! Thanks for the quick turnaround on the update.

lindseydiloreto commented 1 year ago

Great, thanks for confirming! This has been officially released in v1.2.2. 👍