Skip to content

Commit 4e5a36c

Browse files
committed
fix query?
1 parent 424d8b0 commit 4e5a36c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

app/Actions/Photo/DuplicateFinder.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace App\Actions\Photo;
1010

11+
use App\Constants\PhotoAlbum as PA;
1112
use App\Exceptions\Internal\LycheeLogicException;
1213
use App\Exceptions\Internal\QueryBuilderException;
1314
use App\Models\Photo;
@@ -77,7 +78,8 @@ private function query(
7778
}
7879

7980
return Photo::query()
80-
->join('base_albums', 'base_albums.id', '=', 'photos.album_id')
81+
->join(PA::PHOTO_ALBUM, PA::PHOTO_ID, '=', 'photos.id')
82+
->join('base_albums', 'base_albums.id', '=', PA::ALBUM_ID)
8183
->join(
8284
'size_variants', 'size_variants.photo_id', '=', 'photos.id', 'left'
8385
)
@@ -104,12 +106,14 @@ private function getDuplicatesIdsQuery(
104106
bool $must_have_same_title,
105107
): Builder {
106108
return DB::table('photos', 'p1')->select('p1.id')
109+
->joinSub(DB::table(PA::PHOTO_ALBUM), 'pa1', 'pa1.photo_id', '=', 'p1.id', 'left')
107110
->join(
108111
'photos as p2',
109112
fn ($join) => $join->on('p1.id', '<>', 'p2.id')
113+
->joinSub(DB::table(PA::PHOTO_ALBUM), 'pa2', 'pa2.photo_id', '=', 'p2.id', 'left')
110114
->when($must_have_same_title, fn ($q) => $q->on('p1.title', '=', 'p2.title'))
111115
->when($must_have_same_checksum, fn ($q) => $q->on('p1.checksum', '=', 'p2.checksum'))
112-
->when($must_be_within_same_album, fn ($q) => $q->on('p1.album_id', '=', 'p2.album_id'))
116+
->when($must_be_within_same_album, fn ($q) => $q->on('pa1.album_id', '=', 'pa2.album_id'))
113117
);
114118
}
115119
}

0 commit comments

Comments
 (0)