Retroactive Peak Detection Fix
This commit is contained in:
parent
a1416b232b
commit
139e5c57ff
2 changed files with 25 additions and 19 deletions
|
|
@ -20,6 +20,9 @@ import java.util.UUID;
|
||||||
@Repository
|
@Repository
|
||||||
public interface ActivityRepository extends JpaRepository<Activity, UUID> {
|
public interface ActivityRepository extends JpaRepository<Activity, UUID> {
|
||||||
|
|
||||||
|
@Query("SELECT a.id FROM Activity a")
|
||||||
|
List<UUID> findAllIds();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find all activities for a specific user.
|
* Find all activities for a specific user.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ import net.javahippie.fitpub.model.entity.Peak;
|
||||||
import net.javahippie.fitpub.repository.ActivityPeakRepository;
|
import net.javahippie.fitpub.repository.ActivityPeakRepository;
|
||||||
import net.javahippie.fitpub.repository.ActivityRepository;
|
import net.javahippie.fitpub.repository.ActivityRepository;
|
||||||
import net.javahippie.fitpub.repository.PeakRepository;
|
import net.javahippie.fitpub.repository.PeakRepository;
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
@ -86,32 +84,37 @@ public class PeakDetectionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.info("Starting retroactive peak detection for all activities");
|
// Fetch only IDs to avoid loading huge BLOB fields into memory
|
||||||
|
List<UUID> activityIds = activityRepository.findAllIds();
|
||||||
|
|
||||||
|
log.info("Starting retroactive peak detection for {} activities", activityIds.size());
|
||||||
|
|
||||||
int page = 0;
|
|
||||||
int pageSize = 100;
|
|
||||||
int totalProcessed = 0;
|
int totalProcessed = 0;
|
||||||
int totalPeaksFound = 0;
|
int totalPeaksFound = 0;
|
||||||
|
|
||||||
Page<Activity> activityPage;
|
for (UUID activityId : activityIds) {
|
||||||
do {
|
try {
|
||||||
activityPage = activityRepository.findAll(PageRequest.of(page, pageSize));
|
Activity activity = activityRepository.findById(activityId).orElse(null);
|
||||||
for (Activity activity : activityPage.getContent()) {
|
if (activity == null) continue;
|
||||||
try {
|
|
||||||
List<Peak> peaks = detectPeaksForActivity(activity);
|
List<Peak> peaks = detectPeaksForActivity(activity);
|
||||||
totalPeaksFound += peaks.size();
|
totalPeaksFound += peaks.size();
|
||||||
totalProcessed++;
|
totalProcessed++;
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("Failed peak detection for activity {}: {}", activity.getId(), e.getMessage());
|
if (totalProcessed % 100 == 0) {
|
||||||
|
log.info("Peak backfill progress: processed {} / {} activities, found {} peaks so far",
|
||||||
|
totalProcessed, activityIds.size(), totalPeaksFound);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Failed peak detection for activity {}: {}", activityId, e.getMessage(), e);
|
||||||
|
totalProcessed++;
|
||||||
}
|
}
|
||||||
page++;
|
}
|
||||||
log.info("Peak backfill progress: processed {} / {} activities, found {} peaks so far",
|
|
||||||
totalProcessed, activityPage.getTotalElements(), totalPeaksFound);
|
|
||||||
} while (activityPage.hasNext());
|
|
||||||
|
|
||||||
log.info("Peak backfill complete: processed {} activities, found {} total peak associations",
|
log.info("Peak backfill complete: processed {} activities, found {} total peak associations",
|
||||||
totalProcessed, totalPeaksFound);
|
totalProcessed, totalPeaksFound);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Peak backfill failed: {}", e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
backfillRunning.set(false);
|
backfillRunning.set(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue