1
0
Эх сурвалжийг харах

Merge pull request #2907 from pixelfed/staging

Update StoryService, fix division by zero bug
daniel 3 жил өмнө
parent
commit
82c5e74feb

+ 1 - 0
CHANGELOG.md

@@ -107,6 +107,7 @@
 - Updated StoryComposeController, fix expiry bug. ([7dee8f58](https://github.com/pixelfed/pixelfed/commit/7dee8f58))
 - Updated Profile, fix following count bug. ([ee9f0795](https://github.com/pixelfed/pixelfed/commit/ee9f0795))
 - Updated DirectMessageController, fix autocomplete bug. ([0f00be4d](https://github.com/pixelfed/pixelfed/commit/0f00be4d))
+- Updated StoryService, fix division by zero bug. ([6ae1ba0a](https://github.com/pixelfed/pixelfed/commit/6ae1ba0a))
 -  ([](https://github.com/pixelfed/pixelfed/commit/))
 
 ## [v0.11.0 (2021-06-01)](https://github.com/pixelfed/pixelfed/compare/v0.10.10...v0.11.0)

+ 2 - 2
app/Services/StoryService.php

@@ -121,9 +121,9 @@ class StoryService
 					'sum' => (int) Story::sum('size'),
 					'average' => (int) Story::avg('size')
 				],
-				'avg_spu' => (int) ($total / Story::groupBy('profile_id')->pluck('profile_id')->count()),
+				'avg_spu' => $total ? (int) ($total / Story::groupBy('profile_id')->pluck('profile_id')->count()) : 'N/A',
 				'avg_duration' => (int) floor(Story::avg('duration')),
-				'avg_type' => Story::selectRaw('type, count(id) as count')->groupBy('type')->orderByDesc('count')->first()->type
+				'avg_type' => $total ? Story::selectRaw('type, count(id) as count')->groupBy('type')->orderByDesc('count')->first()->type : 'N/A'
 			];
 		});
 	}