Skip to content

Commit

Permalink
Merge pull request #234 from jamebal/develop
Browse files Browse the repository at this point in the history
perf: 优化用户剩余空间计算
  • Loading branch information
jamebal authored Feb 27, 2025
2 parents d9c4da7 + d8cd984 commit da2aeb5
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,21 +395,23 @@ public String createFile(String username, File file, String userId, Boolean isPu

/**
* 修改文件的最后修改时间
* @param file 文件
*
* @param file 文件
* @param fileExists FileDocument
* @param update Update
* @param update Update
*/
private void updateLastModifiedTime(File file, FileDocument fileExists, Update update) {
LocalDateTime lastModifiedTime = getFileLastModifiedTime(file);
// 判断 fileExists.getUpdateDate() 和 lastModifiedTime是否在1ms内
if (fileExists.getUpdateDate() != null && lastModifiedTime.isEqual(fileExists.getUpdateDate())) {
if (fileExists.getUpdateDate() != null && lastModifiedTime.isEqual(fileExists.getUpdateDate())) {
update.set(UPDATE_DATE, lastModifiedTime);
}
}

/**
* 设置文件的最后修改时间
* @param filePath 文件路径
*
* @param filePath 文件路径
* @param lastModified 最后修改时间
* @throws IOException IO异常
*/
Expand Down Expand Up @@ -756,7 +758,10 @@ public void pushMessageOperationFileSuccess(String fromPath, String toPath, Stri
}

public long occupiedSpace(String userId) {
long space = calculateTotalOccupiedSpace(userId).blockingGet();
Long space = userSpaceCache.get(userId, key -> calculateTotalOccupiedSpace(userId).blockingGet());
if (space == null) {
space = 0L;
}
ConsumerDO consumerDO = userService.userInfoById(userId);
if (consumerDO != null && consumerDO.getQuota() != null) {
if (space >= consumerDO.getQuota() * 1024L * 1024L * 1024L) {
Expand All @@ -782,18 +787,13 @@ public Single<Long> getOccupiedSpaceAsync(String userId, String collectionName)
}

public long getOccupiedSpace(String userId, String collectionName) {
Long space = userSpaceCache.getIfPresent(userId);
if (space != null) {
return space;
}
space = 0L;
Long space = 0L;
List<Bson> list = Arrays.asList(match(eq(IUserService.USER_ID, userId)), group(new BsonNull(), sum(Constants.TOTAL_SIZE, "$size")));
AggregateIterable<Document> aggregateIterable = mongoTemplate.getCollection(collectionName).aggregate(list);
Document doc = aggregateIterable.first();
if (doc != null) {
space = Convert.toLong(doc.get(Constants.TOTAL_SIZE), 0L);
}
userSpaceCache.put(userId, space);
return space;
}

Expand Down

0 comments on commit da2aeb5

Please sign in to comment.