Skip to content

Commit e1c034a

Browse files
committed
Fix newsletter criteria not always selecting all articles
The limit applied in the subquery could cause, that inner join joined top 5 most read articles within the period, and then the parent query filtered articles published within the selected period. That effectivelly caused that if one of the most read articles was published outside of the selected period, criterion excluded it and didn't deliver required number of articles. remp/respekt#378
1 parent 69dc556 commit e1c034a

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

Beam/extensions/beam-module/src/Model/Article.php

+19-12
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,16 @@ public function scopeMostReadByPageviews(Builder $query, Carbon $start, string $
330330
->select(['article_id', DB::raw("sum($getBy) as total_sum")])
331331
->orderByDesc('total_sum');
332332

333+
$query = $query->joinSub($innerQuery, 't', function ($join) {
334+
$join->on('articles.id', '=', 't.article_id');
335+
})
336+
->orderByDesc('t.total_sum');
337+
333338
if ($limit) {
334-
$innerQuery->limit($limit);
339+
$query = $query->limit($limit);
335340
}
336341

337-
return $query->joinSub($innerQuery, 't', function ($join) {
338-
$join->on('articles.id', '=', 't.article_id');
339-
})->orderByDesc('t.total_sum');
342+
return $query;
340343
}
341344

342345
public function scopeMostReadByAveragePaymentAmount(Builder $query, Carbon $start, ?int $limit = null): Builder
@@ -346,13 +349,15 @@ public function scopeMostReadByAveragePaymentAmount(Builder $query, Carbon $star
346349
->select(['article_id', DB::raw('avg(amount) as average')])
347350
->orderByDesc('average');
348351

352+
$query = $query->joinSub($innerQuery, 'c', function ($join) {
353+
$join->on('articles.id', '=', 'c.article_id');
354+
})->orderByDesc('c.average');
355+
349356
if ($limit) {
350-
$innerQuery->limit($limit);
357+
$query = $query->limit($limit);
351358
}
352359

353-
return $query->joinSub($innerQuery, 'c', function ($join) {
354-
$join->on('articles.id', '=', 'c.article_id');
355-
})->orderByDesc('c.average');
360+
return $query;
356361
}
357362

358363
public function scopeMostReadByTotalPaymentAmount(Builder $query, Carbon $start, ?int $limit = null): Builder
@@ -362,13 +367,15 @@ public function scopeMostReadByTotalPaymentAmount(Builder $query, Carbon $start,
362367
->select(['article_id', DB::raw('sum(amount) as average')])
363368
->orderByDesc('average');
364369

370+
$query = $query->joinSub($innerQuery, 'c', function ($join) {
371+
$join->on('articles.id', '=', 'c.article_id');
372+
})->orderByDesc('c.average');
373+
365374
if ($limit) {
366-
$innerQuery->limit($limit);
375+
$query = $query->limit($limit);
367376
}
368377

369-
return $query->joinSub($innerQuery, 'c', function ($join) {
370-
$join->on('articles.id', '=', 'c.article_id');
371-
})->orderByDesc('c.average');
378+
return $query;
372379
}
373380

374381
public function scopeIgnoreAuthorIds(Builder $query, array $authorIds): Builder

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1111
- **IMPORTANT** Removed data of sections "Visitors" and "Google Analytics Reporting", which we removed in the previous version. remp/remp#1349
1212
- Migration removes tables `session_devices` and `session_referers`.
1313
- Changed banner preview components as now include and run custom JS inside of iframe. remp/crm#3353
14-
- Added option to specify api version for gender balance in env. remp/helpdesk#3303
14+
- Added option to specify api version for gender balance in env. remp/helpdesk#3303
15+
- Fixed newsletter criteria not always selecting the desired number of articles. remp/respekt#378
1516

1617
### [Campaign]
1718

0 commit comments

Comments
 (0)