Skip to content

Commit

Permalink
fix: 버그 픽스
Browse files Browse the repository at this point in the history
- update 동시성 문제
  • Loading branch information
kariskan committed Aug 29, 2024
1 parent 7528513 commit 327eeb7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.woowacamp.storage.domain.folder.repository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -74,4 +75,10 @@ void updateParentFolderIdForDelete(@Param("newParentId") int newParentId,
Optional<FolderMetadata> findByIdForShare(@Param("folderId") Long folderId);

List<FolderMetadata> findByOwnerId(Long ownerId);

@Modifying
@Query("""
update FolderMetadata f set f.size = f.size + :fileSize, f.updatedAt = :now where f.id = :id
""")
void updateFolderInfo(@Param("fileSize") long fileSize, @Param("now") LocalDateTime now, @Param("id") Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,7 @@ private void deleteWithBfs(long parentFolderId, List<Long> folderIdListForDelete
List<FolderMetadata> childFolder = folderMetadataRepository.findByParentFolderIdForUpdate(currentFolderId);

// 다음 연산을 위해 Queue 에 offer
childFolder.stream().forEach(folder -> {
folderIdQueue.offer(folder.getId());
});
childFolder.stream().forEach(folder -> folderIdQueue.offer(folder.getId()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,18 @@ public void updateFolderPath(Set<FolderMetadata> sourcePath, Set<FolderMetadata>
LocalDateTime now = LocalDateTime.now();
boolean isExistCommonAncestor = false;
for (var source : sourcePath) {
source.updateUpdatedAt(now);
if (source.equals(commonAncestor)) {
isExistCommonAncestor = true;
}
if (!isExistCommonAncestor) {
source.addSize(-fileSize);
folderMetadataRepository.updateFolderInfo(-fileSize, now, source.getId());
}
}
for (var target : targetPath) {
if (target.equals(commonAncestor)) {
break;
}
target.addSize(fileSize);
target.updateUpdatedAt(now);
folderMetadataRepository.updateFolderInfo(fileSize, now, target.getId());
}
}

Expand Down

0 comments on commit 327eeb7

Please sign in to comment.