optimization sql

This commit is contained in:
Artemy
2025-07-01 15:05:49 +07:00
parent 5883f3e340
commit cdae63b223
10 changed files with 81 additions and 58 deletions
@@ -24,6 +24,7 @@ public class FriendshipsRepository : IFriendshipsRepository
.AsNoTracking()
.Include(x => x.Requester)
.Include(x => x.Addressee)
.AsSplitQuery()
.ToListOrThrowIfEmpty(new NotFoundException("Database is empty"));
}
@@ -33,6 +34,7 @@ public class FriendshipsRepository : IFriendshipsRepository
.AsNoTracking()
.Include(x => x.Requester)
.Include(x => x.Addressee)
.AsSplitQuery()
.FirstOrDefaultAsync(x => x.Id == id)
?? throw new NotFoundByKeyException<Guid>(id, "Friendship with given id was not found");
}
@@ -43,6 +45,7 @@ public class FriendshipsRepository : IFriendshipsRepository
.AsNoTracking()
.Include(x => x.Requester)
.Include(x => x.Addressee)
.AsSplitQuery()
.Where(x => x.RequesterId == userId)
.ToListOrThrowIfEmpty(new NotFoundByKeyException<Guid>(userId, "Friendship with given user id was not found"));
}
@@ -81,11 +84,7 @@ public class FriendshipsRepository : IFriendshipsRepository
);
if (rowsAffected == 0)
throw new NotFoundByKeyException<Guid>(friendship.Id);
}
catch (NotFoundByKeyException<Guid> ex)
{
throw new UpdateException($"Not found friendship by given id {friendship.Id}", ex);
throw new UpdateException($"Not found friendship by given id {friendship.Id}");
}
catch (Exception ex)
{