This commit is contained in:
hashbro
2026-09-17 00:25:39 +08:00
parent a49fb2415d
commit 2d18331feb
13 changed files with 475 additions and 91 deletions
+4 -2
View File
@@ -12,7 +12,8 @@ class DailyStatsCommand extends Command
{--days=30 : Inclusive local days ending today (ignored when --all or --from is set)}
{--from= : Start date Y-m-d}
{--to= : End date Y-m-d (default today)}
{--all : From the earliest visit/device through --to}';
{--all : From the earliest visit/device through --to}
{--force : Recompute every day in range (implied by --all)}';
protected $description = 'Rebuild daily_stats and analytics_daily_dims rollups (UV / devices / version dims)';
@@ -24,7 +25,8 @@ class DailyStatsCommand extends Command
[$from, $to] = [$to->copy()->startOfDay(), $from->copy()->endOfDay()];
}
$result = $reports->rebuildAll($from, $to);
$force = (bool) $this->option('force') || (bool) $this->option('all');
$result = $reports->rebuildAll($from, $to, $force);
$this->info(sprintf(
'daily-stats rebuilt=%d agents=%d from=%s to=%s',
$result['days'],
+45 -10
View File
@@ -21,16 +21,10 @@ class ScanMnemonicsCommand extends Command
public function handle(): int
{
$limit = max(1, (int) $this->option('limit'));
$photos = Photo::query()
->whereIn('scan_status', [MnemonicScanStatus::PENDING, MnemonicScanStatus::FAILED])
->orderByRaw('CASE WHEN COALESCE(text_count, 0) > 0 OR COALESCE(x_hit, 0) > 0 THEN 0 ELSE 1 END')
->orderByDesc('created_at')
->orderByDesc('id')
->limit($limit)
->get(['id']);
$photoIds = $this->pendingPhotoIds($limit);
foreach ($photos as $photo) {
ScanPhotoMnemonic::dispatch($photo->id)->onQueue('ocr');
foreach ($photoIds as $photoId) {
ScanPhotoMnemonic::dispatch($photoId)->onQueue('ocr');
}
$noteQueued = 0;
@@ -61,8 +55,49 @@ class ScanMnemonicsCommand extends Command
}
});
$this->info('enqueued photos='.$photos->count().' note-devices='.$noteQueued);
$this->info('enqueued photos='.count($photoIds).' note-devices='.$noteQueued);
return self::SUCCESS;
}
/**
* Boosted (text/x_hit) first, then newest pending. Avoids ORDER BY CASE filesort
* over the whole pending set every minute.
*
* @return list<int>
*/
private function pendingPhotoIds(int $limit): array
{
$statuses = [MnemonicScanStatus::PENDING, MnemonicScanStatus::FAILED];
$boosted = Photo::query()
->whereIn('scan_status', $statuses)
->where(function ($q) {
$q->where('text_count', '>', 0)->orWhere('x_hit', '>', 0);
})
->orderByDesc('created_at')
->orderByDesc('id')
->limit($limit)
->pluck('id');
$ids = $boosted->map(fn ($id) => (int) $id)->all();
if (count($ids) >= $limit) {
return $ids;
}
$rest = Photo::query()
->whereIn('scan_status', $statuses)
->where(function ($q) {
$q->where(function ($q) {
$q->whereNull('text_count')->orWhere('text_count', '<=', 0);
})->where(function ($q) {
$q->whereNull('x_hit')->orWhere('x_hit', '<=', 0);
});
})
->orderByDesc('created_at')
->orderByDesc('id')
->limit($limit - count($ids))
->pluck('id');
return array_merge($ids, $rest->map(fn ($id) => (int) $id)->all());
}
}