This commit is contained in:
User
2025-01-06 12:58:10 -05:00
parent 489e054614
commit 721192fce7
23 changed files with 227 additions and 197 deletions

View File

@@ -71,13 +71,11 @@ class User extends Authenticatable implements MustVerifyEmail
$userId = $this->id;
// Step 1: Identify records to keep
$idsToKeep = ReadingHistory::query()
->select('reading_histories.id') // Specify table name explicitly
$idsToKeep = ReadingHistory::query()->select('reading_histories.id')
->joinSub(
ReadingHistory::query()
->select('comic_id', 'user_id', 'chapter_id', DB::raw('MIN(created_at) as earliest_created_at'))
->where('user_id', $userId) // Specify user_id with table name
->groupBy('comic_id', 'user_id', 'chapter_id'),
->where('user_id', $userId)->groupBy('comic_id', 'user_id', 'chapter_id'),
'b',
function (JoinClause $join) {
$join->on('reading_histories.comic_id', '=', 'b.comic_id')
@@ -85,14 +83,10 @@ class User extends Authenticatable implements MustVerifyEmail
->on('reading_histories.chapter_id', '=', 'b.chapter_id')
->on('reading_histories.created_at', '=', 'b.earliest_created_at');
}
)
->where('reading_histories.user_id', $userId) // Specify table name explicitly
->pluck('id');
)->where('reading_histories.user_id', $userId)->pluck('id');
// Step 2: Delete duplicates for the user
$deletedCount = ReadingHistory::where('user_id', $userId)
->whereNotIn('id', $idsToKeep)
->delete();
$deletedCount = ReadingHistory::where('user_id', $userId)->whereNotIn('id', $idsToKeep)->delete();
// Return the result as an array
return [