Skip to content

Commit

Permalink
Do not cache courses and topics (#62)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomasz Smolarek <[email protected]>
  • Loading branch information
dyfero and dyfero authored Jan 30, 2024
1 parent f43d624 commit 85731cf
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Metrics/AbstractCoursesMoneySpentMetric.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function calculate(?int $limit = null): Collection
$productTable = (new Product())->getTable();
$productProductableTable = (new ProductProductable())->getTable();

$query = Course::selectRaw($courseTable . '.id, ' . $courseTable . '.title as label, SUM(' . $orderItemTable . '.quantity * ' . $orderItemTable . '.price) as value')
$query = Course::dontCache()->selectRaw($courseTable . '.id, ' . $courseTable . '.title as label, SUM(' . $orderItemTable . '.quantity * ' . $orderItemTable . '.price) as value')
->leftJoin($productProductableTable, fn (JoinClause $join) => $join->where($productProductableTable . '.productable_id', '=', DB::raw($courseTable . '.id'))->where($productProductableTable . '.productable_type', '=', (new Course)->getMorphClass()))
->leftJoin($productTable, fn (JoinClause $join) => $join->where($productTable . '.id', '=', DB::raw($productProductableTable . '.product_id')))
->leftJoin($orderItemTable, fn (JoinClause $join) => $join->where($orderItemTable . '.buyable_id', '=', DB::raw($productTable . '.id'))->where($orderItemTable . '.buyable_type', '=', (new Product())->getMorphClass()))
Expand Down
2 changes: 1 addition & 1 deletion src/Metrics/AbstractCoursesPopularityMetric.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract class AbstractCoursesPopularityMetric extends AbstractCoursesMetric
{
public function calculate(?int $limit = null): Collection
{
$query = Course::withCount(['users'])
$query = Course::dontCache()->withCount(['users'])
->orderBy('users_count', 'DESC')
->take($this->getLimit($limit));

Expand Down
2 changes: 1 addition & 1 deletion src/Metrics/AbstractCoursesSecondsSpentMetric.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function calculate(?int $limit = null): Collection
$topicTable = (new Topic())->getTable();
$courseProgressTable = (new CourseProgress())->getTable();

$query = Course::selectRaw($courseTable . '.id, ' . $courseTable . '.title as label, SUM(' . $courseProgressTable . '.seconds) as value')
$query = Course::dontCache()->selectRaw($courseTable . '.id, ' . $courseTable . '.title as label, SUM(' . $courseProgressTable . '.seconds) as value')
->join($lessonTable, $courseTable . '.id', '=', $lessonTable . '.course_id')
->join($topicTable, $lessonTable . '.id', '=', $topicTable . '.lesson_id')
->join($courseProgressTable, $topicTable . '.id', '=', $courseProgressTable . '.topic_id')
Expand Down
2 changes: 1 addition & 1 deletion src/Metrics/CoursesTopSellingMetric.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function calculate(?int $limit = null): Collection
$productTable = (new Product())->getTable();
$productProductableTable = (new ProductProductable())->getTable();

return Course::selectRaw($courseTable . '.id, ' . $courseTable . ".title as label, SUM(" . $orderItemTable . '.quantity) as value')
return Course::dontCache()->selectRaw($courseTable . '.id, ' . $courseTable . ".title as label, SUM(" . $orderItemTable . '.quantity) as value')
->leftJoin($productProductableTable, fn (JoinClause $join) => $join->where($productProductableTable . '.productable_id', '=', DB::raw($courseTable . '.id'))->where($productProductableTable . '.productable_type', '=', (new Course)->getMorphClass()))
->leftJoin($productTable, fn (JoinClause $join) => $join->where($productTable . '.id', '=', DB::raw($productProductableTable . '.product_id')))
->leftJoin($orderItemTable, fn (JoinClause $join) => $join->where($orderItemTable . '.buyable_id', '=', DB::raw($productTable . '.id'))->where($orderItemTable . '.buyable_type', '=', (new Product())->getMorphClass()))
Expand Down
2 changes: 1 addition & 1 deletion src/Stats/Course/AverageTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function calculate(): int
$courseProgressTable = (new CourseProgress())->getTable();

/** @var Collection $results */
$results = Course::selectRaw($courseTable . '.id, ' . $courseProgressTable . '.user_id, SUM(' . $courseProgressTable . '.seconds) as time')
$results = Course::dontCache()->selectRaw($courseTable . '.id, ' . $courseProgressTable . '.user_id, SUM(' . $courseProgressTable . '.seconds) as time')
->leftJoin($lessonTable, $courseTable . '.id', '=', $lessonTable . '.course_id')
->leftJoin($topicTable, $lessonTable . '.id', '=', $topicTable . '.lesson_id')
->leftJoin($courseProgressTable, $topicTable . '.id', '=', $courseProgressTable . '.topic_id')
Expand Down
2 changes: 1 addition & 1 deletion src/Stats/Course/CourseUsersAndGroupsStat.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(Course $course)

protected function getGroupUsers(): \Illuminate\Support\Collection
{
return $this->formatGroupResult(Topic::query()
return $this->formatGroupResult(Topic::dontCache()
->select(
$this->topicTable . '.id as topic_id',
$this->topicTable . '.title as topic_title',
Expand Down
2 changes: 1 addition & 1 deletion src/Stats/Course/FinishedTopics.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function calculate(): array

private function getBaseQuery(): Builder
{
return Topic::query()
return Topic::dontCache()
->select(
$this->topicTable . '.id as topic_id',
$this->topicTable . '.title as topic_title',
Expand Down

0 comments on commit 85731cf

Please sign in to comment.