Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#581 [feat] 글모임 정보 받아올 시 분산락 위치 변경 #583

Merged
merged 2 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ private Set<MoimCuriousWriter> getMoimCuriousWriter(final List<PostAndCuriousCou

@CachePut(value = "moimPopularInfo", key = "#moim.id")
public MoimPopularInfo setMostPopularInfoOfMoim(final Moim moim) {
distributedLock.getLock("MOIM_POPULAR_LOCK");

List<PostAndCuriousCountInLastWeek> mostCuriousPostsInLastWeek = curiousRetriever.findMostCuriousPostsInLastWeek(moim);

Expand All @@ -59,7 +58,7 @@ public MoimPopularInfo setMostPopularInfoOfMoim(final Moim moim) {

moimPopularInfoRepository.saveAndFlush(moimPopularInfo);

distributedLock.afterLock("MOIM_POPULAR_LOCK");
distributedLock.afterLock("MOIM_POPULAR_LOCK" + moim.getId());

return moimPopularInfo;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mile.moim.service.popular;

import com.mile.common.CacheService;
import com.mile.common.lock.DistributedLock;
import com.mile.moim.domain.Moim;
import com.mile.moim.domain.popular.MoimPopularInfo;
import com.mile.moim.repository.MoimPopularInfoRepository;
Expand All @@ -17,13 +18,17 @@ public class MoimPopularInfoService {
private final MoimPopularInfoRepository moimPopularInfoRepository;
private final MoimPopularInfoRegister moimPopularInfoRegister;
private final SendMessageModule sendMessageModule;
private final DistributedLock distributedLock;
private final CacheService cacheService;


@Cacheable(value = "moimPopularInfo", key = "#moim.id")
public MoimPopularInfo getMoimPopularInfo(final Moim moim) {
return moimPopularInfoRepository.findByMoimId(moim.getId()).orElseGet(
() -> moimPopularInfoRegister.setMostPopularInfoOfMoim(moim)
() -> {
distributedLock.getLock("MOIM_POPULAR_LOCK" + moim.getId());
return moimPopularInfoRegister.setMostPopularInfoOfMoim(moim);
}
);
}

Expand Down
Loading