Skip to content

Commit

Permalink
fix: "division by zero" when searching for collections to nominate (#658
Browse files Browse the repository at this point in the history
)
  • Loading branch information
crnkovic authored Feb 8, 2024
1 parent 2359a83 commit b272719
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/Api/VotableCollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public function index(FilterableCollectionRequest $request): JsonResponse
*/
private function getVotedCollection(User $user, EloquentCollection $collections): ?VotableCollectionData
{
$collection = Collection::votable()
->withCount(['votes' => fn ($q) => $q->inCurrentMonth()])
$collection = Collection::query()
->withCount(['nfts', 'votes' => fn ($q) => $q->inCurrentMonth()])
->with('network.nativeToken')
->votedByUserInCurrentMonth($user)
->first();
Expand Down
5 changes: 3 additions & 2 deletions app/Models/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,12 +631,13 @@ public function scopeAddFloorPriceChange(Builder $query): Builder
SELECT
(AVG(case when fp1.retrieved_at >= CURRENT_DATE then fp1.floor_price end) -
AVG(case when fp1.retrieved_at >= CURRENT_DATE - INTERVAL '1 DAY' AND fp1.retrieved_at < CURRENT_DATE then fp1.floor_price end)) /
AVG(case when fp1.retrieved_at >= CURRENT_DATE - INTERVAL '1 DAY' AND fp1.retrieved_at < CURRENT_DATE then fp1.floor_price end) * 100
NULLIF(AVG(case when fp1.retrieved_at >= CURRENT_DATE - INTERVAL '1 DAY' AND fp1.retrieved_at < CURRENT_DATE then fp1.floor_price end) * 100, 0)
FROM
floor_price_history fp1
WHERE
fp1.collection_id = collections.id AND
fp1.retrieved_at >= CURRENT_DATE - INTERVAL '1 DAY') AS price_change_24h
fp1.retrieved_at >= CURRENT_DATE - INTERVAL '1 DAY'
) AS price_change_24h
")
);
}
Expand Down

0 comments on commit b272719

Please sign in to comment.