Add limit to auth user expressions

This commit is contained in:
Adam Gastineau
2026-07-24 12:11:57 -07:00
parent 21b9f1389c
commit 2d44994e68
4 changed files with 15 additions and 6 deletions
@@ -30,7 +30,9 @@ class DriftLocalAssetRepository extends DriftDatabaseRepository {
_db.remoteAssetEntity,
_db.localAssetEntity.checksum.equalsExp(_db.remoteAssetEntity.checksum) &
_db.remoteAssetEntity.ownerId.isInQuery(
_db.selectOnly(_db.authUserEntity)..addColumns([_db.authUserEntity.id]),
_db.selectOnly(_db.authUserEntity)
..addColumns([_db.authUserEntity.id])
..limit(1),
),
useColumns: false,
),
@@ -64,7 +64,11 @@ class RemoteAssetRepository extends DriftDatabaseRepository {
..where(
(row) =>
row.checksum.equals(checksum) &
row.ownerId.isInQuery(_db.selectOnly(_db.authUserEntity)..addColumns([_db.authUserEntity.id])),
row.ownerId.isInQuery(
_db.selectOnly(_db.authUserEntity)
..addColumns([_db.authUserEntity.id])
..limit(1),
),
)
..limit(1);
@@ -164,7 +164,9 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
_db.remoteAssetEntity,
_db.localAssetEntity.checksum.equalsExp(_db.remoteAssetEntity.checksum) &
_db.remoteAssetEntity.ownerId.isInQuery(
_db.selectOnly(_db.authUserEntity)..addColumns([_db.authUserEntity.id]),
_db.selectOnly(_db.authUserEntity)
..addColumns([_db.authUserEntity.id])
..limit(1),
),
useColumns: false,
),
@@ -58,10 +58,11 @@ void main() {
expect(result.storage, AssetState.local);
});
test('allows the current user to have multiple remote rows for one checksum (#29973)', () async {
// A single user can have many remote assets with the same checksum (their upload + external library copy)
test('allows the current user to have access to multiple remote rows for one checksum (#29973)', () async {
// A single user can have their own remote asset, a partner's remote asset, and a local asset all with the same checksum
const checksum = 'multi-library';
await ctx.newRemoteAsset(ownerId: userId, checksum: checksum);
final partner = await ctx.newUser();
await ctx.newRemoteAsset(ownerId: partner.id, checksum: checksum);
await ctx.newRemoteAsset(ownerId: userId, checksum: checksum);
final local = await ctx.newLocalAsset(checksum: checksum);