fix(infra): add @Transactional to incrementDownloadCount

The @Modifying query requires a transaction context to execute.
Adding @Transactional at the repository method level ensures the
update query runs within a transaction, even when called from
async event listeners.

This fixes the issue where download counts were not being incremented
after skill downloads due to TransactionRequiredException.
This commit is contained in:
wowo-zZ 2026-03-14 17:03:58 +08:00
parent 56e7baed15
commit 871278d43a

View file

@ -10,6 +10,7 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
@ -29,6 +30,7 @@ public interface SkillJpaRepository extends JpaRepository<Skill, Long>, SkillRep
List<Skill> findByOwnerId(String ownerId);
@Modifying
@Transactional
@Query("UPDATE Skill s SET s.downloadCount = s.downloadCount + 1 WHERE s.id = :skillId")
void incrementDownloadCount(@Param("skillId") Long skillId);
}