Skip to content

Commit

Permalink
feat: 생성된 url인지 MySQL이 아닌 Redis로 확인하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
deepredk committed Oct 17, 2023
1 parent 04ed324 commit 6ad51ce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package it.numble.hittracker.repository;

import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class IsCreatedUrlRepository {
private final RedisTemplate<String, String> redisTemplate;

public Long create(String url) {
return redisTemplate
.opsForSet()
.add("created_url", url);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import it.numble.hittracker.controller.dto.UrlHitInfoDto;
import it.numble.hittracker.entity.DailyHitLog;
import it.numble.hittracker.entity.Url;
import it.numble.hittracker.repository.IsCreatedUrlRepository;
import it.numble.hittracker.repository.DailyHitLogRepository;
import it.numble.hittracker.repository.HitRepository;
import it.numble.hittracker.repository.UrlRepository;
Expand All @@ -21,6 +22,7 @@ public class HitTrackerService {
private final UrlRepository urlRepository;
private final DailyHitLogRepository dailyHitLogRepository;
private final HitRepository hitRepository;
private final IsCreatedUrlRepository isCreatedUrlRepository;

public UrlHitInfoDto getHitInfo(String url) {
if (!isExistsUrl(url)) {
Expand Down Expand Up @@ -68,12 +70,13 @@ private void deleteOldDailyHitLogs(LocalDate today) {
.forEach(dailyHitLogRepository::delete);
}

@Async
private void track(String url) {
Url urlBeingTracked = new Url(url);
urlRepository.save(urlBeingTracked);
}

private boolean isExistsUrl(String url) {
return urlRepository.existsByUrl(url);
return isCreatedUrlRepository.create(url) == 1L;
}
}

0 comments on commit 6ad51ce

Please sign in to comment.