Skip to content

Commit

Permalink
Backport v5 bugfix showing wrong result in sidebar (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Numkil authored Sep 6, 2024
2 parents f9d59a6 + 987b58c commit 53e3934
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 61 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for carbon-tracker

## 4.1.2 - 2024-09-02
### Backport v5 bugfix
- Website carbon sidebar always showed the OLDEST carbon result instead of the NEWEST

## 4.1.1 - 2024-09-02
### Added
- Fixed ttr on queue job
Expand All @@ -21,4 +25,4 @@
- Fixed issue with failing jobs on multi-site installs

## 4.0.0 - 2024-01-02
- Initial release 🚀
- Initial release 🚀
107 changes: 53 additions & 54 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
{
"name": "statikbe/craft-carbon-tracker",
"description": "Carbon tracker aims to raise awareness of the carbon emissions created by webpages, by displaying these insights along side the content in Craft's control panel.",
"type": "craft-plugin",
"version": "4.1.1",
"license": "mit",
"support": {
"email": "[email protected]",
"issues": "https://github.com/statikbe/craft-carbon-tracker/issues?state=open",
"source": "https://github.com/statikbe/craft-carbon-tracker",
"docs": "https://github.com/statikbe/craft-carbon-tracker",
"rss": "https://github.com/statikbe/craft-carbon-tracker/releases.atom"
},
"require": {
"php": ">=8.0.2",
"craftcms/cms": "^4.5.0"
},
"require-dev": {
"craftcms/ecs": "dev-main",
"craftcms/phpstan": "dev-main"
},
"authors": [
{
"name": "Jan Henckens",
"email": "[email protected]",
"homepage": "https://www.statik.de"
}
],
"autoload": {
"psr-4": {
"statikbe\\carbontracker\\": "src/"
}
},
"extra": {
"handle": "carbon-tracker",
"name": "Carbon Emissions Tracker",
"developer": "Statik.be",
"documentationUrl": "https://github.com/statikbe/craft-carbon-tracker",
"class": "statikbe\\carbontracker\\CarbonTracker"
},
"scripts": {
"check-cs": "ecs check --ansi",
"fix-cs": "ecs check --ansi --fix",
"phpstan": "phpstan --memory-limit=1G",
"ci": "ecs check --ansi --fix && phpstan --memory-limit=1G"
"name": "statikbe/craft-carbon-tracker",
"description": "Carbon tracker aims to raise awareness of the carbon emissions created by webpages, by displaying these insights along side the content in Craft's control panel.",
"type": "craft-plugin",
"version": "4.1.2",
"license": "mit",
"support": {
"email": "[email protected]",
"issues": "https://github.com/statikbe/craft-carbon-tracker/issues?state=open",
"source": "https://github.com/statikbe/craft-carbon-tracker",
"docs": "https://github.com/statikbe/craft-carbon-tracker",
"rss": "https://github.com/statikbe/craft-carbon-tracker/releases.atom"
},
"require": {
"php": ">=8.0.2",
"craftcms/cms": "^4.5.0"
},
"require-dev": {
"craftcms/ecs": "dev-main",
"craftcms/phpstan": "dev-main"
},
"authors": [
{
"name": "Jan Henckens",
"email": "[email protected]",
"homepage": "https://www.statik.de"
}
],
"autoload": {
"psr-4": {
"statikbe\\carbontracker\\": "src/"
}
},
"extra": {
"handle": "carbon-tracker",
"name": "Carbon Emissions Tracker",
"developer": "Statik.be",
"documentationUrl": "https://github.com/statikbe/craft-carbon-tracker",
"class": "statikbe\\carbontracker\\CarbonTracker"
},
"scripts": {
"check-cs": "ecs check --ansi",
"fix-cs": "ecs check --ansi --fix",
"phpstan": "phpstan --memory-limit=1G",
"ci": "ecs check --ansi --fix && phpstan --memory-limit=1G"
},
"config": {
"sort-packages": true,
"platform": {
"php": "8.0.2"
},
"config": {
"sort-packages": true,
"platform": {
"php": "8.0.2"
},
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
}
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
}
}
}

14 changes: 8 additions & 6 deletions src/services/StatsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ class StatsService extends Component
{
public function getDataForEntry(Entry $entry): SiteStatisticsModel|bool
{
$record = SiteStatisticsRecord::findOne(['entryId' => $entry->id, 'siteId' => $entry->siteId]);

if (!$record) {
// Search again without the siteId
$record = SiteStatisticsRecord::findOne(['entryId' => $entry->id]);
if (!$record) {
/** @var SiteStatisticsRecord|null $record */
$record = SiteStatisticsRecord::find()->where(['entryId' => $entry->id])->andWhere(['siteId' => $entry->siteId])->orderBy('id DESC')->one();

// INFO: if we don't find a record, we'll try to find one without the siteId
if ($record === null) {
/** @var SiteStatisticsRecord|null $record */
$record = SiteStatisticsRecord::find()->where(['entryId' => $entry->id])->orderBy('id DESC')->one();
if ($record === null) {
return false;
}
}
Expand Down

0 comments on commit 53e3934

Please sign in to comment.