Merge pull request 'Fixed auto file cleanup not working' (#21) from bugfix/file-cron-auto-delete into main
Reviewed-on: https://git.walzen665.de/Walzen665/sharepulse/pulls/21
This commit is contained in:
commit
f65a0d0e22
@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
|
||||
@Repository
|
||||
@ -36,7 +38,7 @@ public class FileUploadRepository {
|
||||
Type type = new TypeToken<Map<String, Object>>(){}.getType();
|
||||
Map<String, Object> map = gson.fromJson(json, type);
|
||||
|
||||
long uploadDateTimestamp = fileUpload.getUploadDate().getTime();
|
||||
long uploadDateTimestamp = fileUpload.getUploadDate().getTime() / 1000;
|
||||
map.put("uploadDate", uploadDateTimestamp);
|
||||
|
||||
r.db("sharepulse").table("file_uploads").insert(map).run(connection);
|
||||
@ -61,7 +63,7 @@ public class FileUploadRepository {
|
||||
Type type = new TypeToken<Map<String, Object>>(){}.getType();
|
||||
Map<String, Object> map = gson.fromJson(json, type);
|
||||
|
||||
long uploadDateTimestamp = updatedFileUpload.getUploadDate().getTime();
|
||||
long uploadDateTimestamp = updatedFileUpload.getUploadDate().getTime() / 1000;
|
||||
map.put("uploadDate", uploadDateTimestamp);
|
||||
|
||||
String fileId = updatedFileUpload.getFileId();
|
||||
@ -79,32 +81,25 @@ public class FileUploadRepository {
|
||||
.run(connection);
|
||||
}
|
||||
|
||||
// This query filters all file uploads that are older than 24 hours from the file_uplaods table (not the expired_file_uploads table)
|
||||
public List<FileUpload> findAllExpiredActiveFileUploads() {
|
||||
|
||||
long timestamp = getOneMinuteAgoTimestamp();
|
||||
|
||||
return r.db("sharepulse").table("file_uploads")
|
||||
public List<FileUpload> getAllExpiredFileUploads() {
|
||||
long timestamp = getTimestamp24HoursAgo();
|
||||
List<FileUpload> olderFiles = r.db("sharepulse").table("file_uploads")
|
||||
.filter(row -> row.g("uploadDate").lt(timestamp))
|
||||
.run(connection, FileUpload.class)
|
||||
.toList();
|
||||
return olderFiles;
|
||||
}
|
||||
|
||||
public List<FileUpload> findAll() {
|
||||
return r.db("sharepulse").table("file_uploads")
|
||||
.run(connection, FileUpload.class)
|
||||
.toList();
|
||||
private long getTimestamp24HoursAgo() {
|
||||
Instant now = Instant.now();
|
||||
Instant oneMinuteAgo = now.minus(24, ChronoUnit.HOURS);
|
||||
return oneMinuteAgo.toEpochMilli();
|
||||
}
|
||||
|
||||
private long get24HoursAgoTimestamp() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.HOUR, -24);
|
||||
return calendar.getTimeInMillis() / 1000;
|
||||
// For testing only
|
||||
private long getTimestampOneMinuteAgo() {
|
||||
Instant now = Instant.now();
|
||||
Instant oneMinuteAgo = now.minus(1, ChronoUnit.MINUTES);
|
||||
return oneMinuteAgo.toEpochMilli();
|
||||
}
|
||||
|
||||
private long getOneMinuteAgoTimestamp() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.MINUTE, -1); // Subtract 1 minute
|
||||
return calendar.getTimeInMillis() / 1000; // Convert milliseconds to seconds (Unix timestamp)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user