fix(repositories): add automatic flushing to delete methods in various repositories (#791)
This commit is contained in:
@@ -2,8 +2,10 @@ package org.booklore.repository;
|
|||||||
|
|
||||||
import org.booklore.model.entity.AnnotationEntity;
|
import org.booklore.model.entity.AnnotationEntity;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -30,7 +32,10 @@ public interface AnnotationRepository extends JpaRepository<AnnotationEntity, Lo
|
|||||||
|
|
||||||
long countByBookIdAndUserId(Long bookId, Long userId);
|
long countByBookIdAndUserId(Long bookId, Long userId);
|
||||||
|
|
||||||
void deleteByBookIdAndUserId(Long bookId, Long userId);
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
|
@Transactional
|
||||||
|
@Query("DELETE FROM AnnotationEntity a WHERE a.bookId = :bookId AND a.userId = :userId")
|
||||||
|
void deleteByBookIdAndUserId(@Param("bookId") Long bookId, @Param("userId") Long userId);
|
||||||
|
|
||||||
@Query("SELECT a FROM AnnotationEntity a JOIN FETCH a.book b JOIN FETCH b.metadata WHERE a.userId = :userId ORDER BY a.createdAt DESC")
|
@Query("SELECT a FROM AnnotationEntity a JOIN FETCH a.book b JOIN FETCH b.metadata WHERE a.userId = :userId ORDER BY a.createdAt DESC")
|
||||||
List<AnnotationEntity> findByUserIdOrderByCreatedAtDesc(@Param("userId") Long userId);
|
List<AnnotationEntity> findByUserIdOrderByCreatedAtDesc(@Param("userId") Long userId);
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ public interface BookMetadataRepository extends JpaRepository<BookMetadataEntity
|
|||||||
@Query("SELECT m FROM BookMetadataEntity m WHERE m.bookId IN :bookIds")
|
@Query("SELECT m FROM BookMetadataEntity m WHERE m.bookId IN :bookIds")
|
||||||
List<BookMetadataEntity> getMetadataForBookIds(@Param("bookIds") List<Long> bookIds);
|
List<BookMetadataEntity> getMetadataForBookIds(@Param("bookIds") List<Long> bookIds);
|
||||||
|
|
||||||
@Modifying
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
@Transactional
|
@Transactional
|
||||||
@Query("UPDATE BookMetadataEntity m SET m.coverUpdatedOn = :timestamp WHERE m.bookId = :bookId")
|
@Query("UPDATE BookMetadataEntity m SET m.coverUpdatedOn = :timestamp WHERE m.bookId = :bookId")
|
||||||
void updateCoverTimestamp(@Param("bookId") Long bookId, @Param("timestamp") Instant timestamp);
|
void updateCoverTimestamp(@Param("bookId") Long bookId, @Param("timestamp") Instant timestamp);
|
||||||
|
|
||||||
@Modifying
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
@Transactional
|
@Transactional
|
||||||
@Query("UPDATE BookMetadataEntity m SET m.audiobookCoverUpdatedOn = :timestamp WHERE m.bookId = :bookId")
|
@Query("UPDATE BookMetadataEntity m SET m.audiobookCoverUpdatedOn = :timestamp WHERE m.bookId = :bookId")
|
||||||
void updateAudiobookCoverTimestamp(@Param("bookId") Long bookId, @Param("timestamp") Instant timestamp);
|
void updateAudiobookCoverTimestamp(@Param("bookId") Long bookId, @Param("timestamp") Instant timestamp);
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package org.booklore.repository;
|
|||||||
|
|
||||||
import org.booklore.model.entity.BookNoteV2Entity;
|
import org.booklore.model.entity.BookNoteV2Entity;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -30,7 +32,10 @@ public interface BookNoteV2Repository extends JpaRepository<BookNoteV2Entity, Lo
|
|||||||
|
|
||||||
long countByBookIdAndUserId(Long bookId, Long userId);
|
long countByBookIdAndUserId(Long bookId, Long userId);
|
||||||
|
|
||||||
void deleteByBookIdAndUserId(Long bookId, Long userId);
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
|
@Transactional
|
||||||
|
@Query("DELETE FROM BookNoteV2Entity n WHERE n.bookId = :bookId AND n.userId = :userId")
|
||||||
|
void deleteByBookIdAndUserId(@Param("bookId") Long bookId, @Param("userId") Long userId);
|
||||||
|
|
||||||
@Query("SELECT n FROM BookNoteV2Entity n JOIN FETCH n.book b JOIN FETCH b.metadata WHERE n.userId = :userId ORDER BY n.createdAt DESC")
|
@Query("SELECT n FROM BookNoteV2Entity n JOIN FETCH n.book b JOIN FETCH b.metadata WHERE n.userId = :userId ORDER BY n.createdAt DESC")
|
||||||
List<BookNoteV2Entity> findByUserIdOrderByCreatedAtDesc(@Param("userId") Long userId);
|
List<BookNoteV2Entity> findByUserIdOrderByCreatedAtDesc(@Param("userId") Long userId);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public interface BookdropFileRepository extends JpaRepository<BookdropFileEntity
|
|||||||
long countByStatus(Status status);
|
long countByStatus(Status status);
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Modifying
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
@Query("DELETE FROM BookdropFileEntity f WHERE f.filePath LIKE CONCAT(:prefix, '%')")
|
@Query("DELETE FROM BookdropFileEntity f WHERE f.filePath LIKE CONCAT(:prefix, '%')")
|
||||||
int deleteAllByFilePathStartingWith(@Param("prefix") String prefix);
|
int deleteAllByFilePathStartingWith(@Param("prefix") String prefix);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
package org.booklore.repository;
|
package org.booklore.repository;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
|
||||||
import org.booklore.model.entity.ComicCreatorMappingEntity;
|
import org.booklore.model.entity.ComicCreatorMappingEntity;
|
||||||
import org.booklore.model.enums.ComicCreatorRole;
|
import org.booklore.model.enums.ComicCreatorRole;
|
||||||
@@ -12,5 +16,8 @@ public interface ComicCreatorMappingRepository extends JpaRepository<ComicCreato
|
|||||||
|
|
||||||
List<ComicCreatorMappingEntity> findByComicMetadataBookIdAndRole(Long bookId, ComicCreatorRole role);
|
List<ComicCreatorMappingEntity> findByComicMetadataBookIdAndRole(Long bookId, ComicCreatorRole role);
|
||||||
|
|
||||||
void deleteByComicMetadataBookId(Long bookId);
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
|
@Transactional
|
||||||
|
@Query("DELETE FROM ComicCreatorMappingEntity m WHERE m.comicMetadata.bookId = :bookId")
|
||||||
|
void deleteByComicMetadataBookId(@Param("bookId") Long bookId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public interface EmailRecipientV2Repository extends JpaRepository<EmailRecipient
|
|||||||
|
|
||||||
List<EmailRecipientV2Entity> findAllByUserId(Long userId);
|
List<EmailRecipientV2Entity> findAllByUserId(Long userId);
|
||||||
|
|
||||||
@Modifying
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
@Transactional
|
@Transactional
|
||||||
@Query("UPDATE EmailRecipientV2Entity e SET e.defaultRecipient = false WHERE e.defaultRecipient = true AND e.userId = :userId")
|
@Query("UPDATE EmailRecipientV2Entity e SET e.defaultRecipient = false WHERE e.defaultRecipient = true AND e.userId = :userId")
|
||||||
void updateAllRecipientsToNonDefault(Long userId);
|
void updateAllRecipientsToNonDefault(Long userId);
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ import org.springframework.stereotype.Repository;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface KoboDeletedBookProgressRepository extends JpaRepository<KoboDeletedBookProgressEntity, Long> {
|
public interface KoboDeletedBookProgressRepository extends JpaRepository<KoboDeletedBookProgressEntity, Long> {
|
||||||
|
|
||||||
@Modifying
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
@Transactional
|
@Transactional
|
||||||
@Query("DELETE FROM KoboDeletedBookProgressEntity p WHERE p.snapshotId = :snapshotId AND p.userId = :userId")
|
@Query("DELETE FROM KoboDeletedBookProgressEntity p WHERE p.snapshotId = :snapshotId AND p.userId = :userId")
|
||||||
void deleteBySnapshotIdAndUserId(@Param("snapshotId") String snapshotId, @Param("userId") Long userId);
|
void deleteBySnapshotIdAndUserId(@Param("snapshotId") String snapshotId, @Param("userId") Long userId);
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
package org.booklore.repository;
|
package org.booklore.repository;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
|
||||||
import org.booklore.model.entity.OidcSessionEntity;
|
import org.booklore.model.entity.OidcSessionEntity;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
@@ -19,7 +23,13 @@ public interface OidcSessionRepository extends JpaRepository<OidcSessionEntity,
|
|||||||
|
|
||||||
List<OidcSessionEntity> findByUserIdAndRevokedFalse(Long userId);
|
List<OidcSessionEntity> findByUserIdAndRevokedFalse(Long userId);
|
||||||
|
|
||||||
void deleteByRevokedTrueAndCreatedAtBefore(Instant cutoff);
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
|
@Transactional
|
||||||
|
@Query("DELETE FROM OidcSessionEntity s WHERE s.revoked = true AND s.createdAt < :cutoff")
|
||||||
|
void deleteByRevokedTrueAndCreatedAtBefore(@Param("cutoff") Instant cutoff);
|
||||||
|
|
||||||
void deleteByCreatedAtBefore(Instant cutoff);
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
|
@Transactional
|
||||||
|
@Query("DELETE FROM OidcSessionEntity s WHERE s.createdAt < :cutoff")
|
||||||
|
void deleteByCreatedAtBefore(@Param("cutoff") Instant cutoff);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
package org.booklore.repository;
|
package org.booklore.repository;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
|
||||||
import org.booklore.model.entity.PdfAnnotationEntity;
|
import org.booklore.model.entity.PdfAnnotationEntity;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
@@ -9,5 +13,8 @@ public interface PdfAnnotationRepository extends JpaRepository<PdfAnnotationEnti
|
|||||||
|
|
||||||
Optional<PdfAnnotationEntity> findByBookIdAndUserId(Long bookId, Long userId);
|
Optional<PdfAnnotationEntity> findByBookIdAndUserId(Long bookId, Long userId);
|
||||||
|
|
||||||
void deleteByBookIdAndUserId(Long bookId, Long userId);
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
|
@Transactional
|
||||||
|
@Query("DELETE FROM PdfAnnotationEntity a WHERE a.bookId = :bookId AND a.userId = :userId")
|
||||||
|
void deleteByBookIdAndUserId(@Param("bookId") Long bookId, @Param("userId") Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
package org.booklore.repository;
|
package org.booklore.repository;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
|
||||||
import org.booklore.model.entity.BookLoreUserEntity;
|
import org.booklore.model.entity.BookLoreUserEntity;
|
||||||
import org.booklore.model.entity.RefreshTokenEntity;
|
import org.booklore.model.entity.RefreshTokenEntity;
|
||||||
@@ -10,5 +14,8 @@ import java.util.Optional;
|
|||||||
public interface RefreshTokenRepository extends JpaRepository<RefreshTokenEntity, Long> {
|
public interface RefreshTokenRepository extends JpaRepository<RefreshTokenEntity, Long> {
|
||||||
Optional<RefreshTokenEntity> findByToken(String token);
|
Optional<RefreshTokenEntity> findByToken(String token);
|
||||||
List<RefreshTokenEntity> findAllByUserAndRevokedFalse(BookLoreUserEntity user);
|
List<RefreshTokenEntity> findAllByUserAndRevokedFalse(BookLoreUserEntity user);
|
||||||
void deleteByUser(BookLoreUserEntity user);
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
|
@Transactional
|
||||||
|
@Query("DELETE FROM RefreshTokenEntity t WHERE t.user = :user")
|
||||||
|
void deleteByUser(@Param("user") BookLoreUserEntity user);
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-2
@@ -4,8 +4,10 @@ import org.booklore.model.entity.UserContentRestrictionEntity;
|
|||||||
import org.booklore.model.enums.ContentRestrictionMode;
|
import org.booklore.model.enums.ContentRestrictionMode;
|
||||||
import org.booklore.model.enums.ContentRestrictionType;
|
import org.booklore.model.enums.ContentRestrictionType;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -21,9 +23,15 @@ public interface UserContentRestrictionRepository extends JpaRepository<UserCont
|
|||||||
Optional<UserContentRestrictionEntity> findByUserIdAndRestrictionTypeAndValue(
|
Optional<UserContentRestrictionEntity> findByUserIdAndRestrictionTypeAndValue(
|
||||||
Long userId, ContentRestrictionType restrictionType, String value);
|
Long userId, ContentRestrictionType restrictionType, String value);
|
||||||
|
|
||||||
void deleteByUserId(Long userId);
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
|
@Transactional
|
||||||
|
@Query("DELETE FROM UserContentRestrictionEntity r WHERE r.user.id = :userId")
|
||||||
|
void deleteByUserId(@Param("userId") Long userId);
|
||||||
|
|
||||||
void deleteByUserIdAndRestrictionType(Long userId, ContentRestrictionType type);
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
|
@Transactional
|
||||||
|
@Query("DELETE FROM UserContentRestrictionEntity r WHERE r.user.id = :userId AND r.restrictionType = :type")
|
||||||
|
void deleteByUserIdAndRestrictionType(@Param("userId") Long userId, @Param("type") ContentRestrictionType type);
|
||||||
|
|
||||||
@Query("SELECT r FROM UserContentRestrictionEntity r WHERE r.user.id = :userId AND r.restrictionType = :type AND r.mode = :mode")
|
@Query("SELECT r FROM UserContentRestrictionEntity r WHERE r.user.id = :userId AND r.restrictionType = :type AND r.mode = :mode")
|
||||||
List<UserContentRestrictionEntity> findByUserIdAndTypeAndMode(
|
List<UserContentRestrictionEntity> findByUserIdAndTypeAndMode(
|
||||||
|
|||||||
+8
-1
@@ -1,4 +1,8 @@
|
|||||||
package org.booklore.repository;
|
package org.booklore.repository;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
|
||||||
import org.booklore.model.entity.UserEmailProviderPreferenceEntity;
|
import org.booklore.model.entity.UserEmailProviderPreferenceEntity;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
@@ -11,6 +15,9 @@ public interface UserEmailProviderPreferenceRepository extends JpaRepository<Use
|
|||||||
|
|
||||||
Optional<UserEmailProviderPreferenceEntity> findByUserId(Long userId);
|
Optional<UserEmailProviderPreferenceEntity> findByUserId(Long userId);
|
||||||
|
|
||||||
void deleteByUserId(Long userId);
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
|
@Transactional
|
||||||
|
@Query("DELETE FROM UserEmailProviderPreferenceEntity p WHERE p.userId = :userId")
|
||||||
|
void deleteByUserId(@Param("userId") Long userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user