Fixed auto file cleanup not working
This commit is contained in:
parent
6f550c0787
commit
e73a2e6e8d
@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
@ -36,7 +38,7 @@ public class FileUploadRepository {
|
|||||||
Type type = new TypeToken<Map<String, Object>>(){}.getType();
|
Type type = new TypeToken<Map<String, Object>>(){}.getType();
|
||||||
Map<String, Object> map = gson.fromJson(json, type);
|
Map<String, Object> map = gson.fromJson(json, type);
|
||||||
|
|
||||||
long uploadDateTimestamp = fileUpload.getUploadDate().getTime();
|
long uploadDateTimestamp = fileUpload.getUploadDate().getTime() / 1000;
|
||||||
map.put("uploadDate", uploadDateTimestamp);
|
map.put("uploadDate", uploadDateTimestamp);
|
||||||
|
|
||||||
r.db("sharepulse").table("file_uploads").insert(map).run(connection);
|
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();
|
Type type = new TypeToken<Map<String, Object>>(){}.getType();
|
||||||
Map<String, Object> map = gson.fromJson(json, type);
|
Map<String, Object> map = gson.fromJson(json, type);
|
||||||
|
|
||||||
long uploadDateTimestamp = updatedFileUpload.getUploadDate().getTime();
|
long uploadDateTimestamp = updatedFileUpload.getUploadDate().getTime() / 1000;
|
||||||
map.put("uploadDate", uploadDateTimestamp);
|
map.put("uploadDate", uploadDateTimestamp);
|
||||||
|
|
||||||
String fileId = updatedFileUpload.getFileId();
|
String fileId = updatedFileUpload.getFileId();
|
||||||
@ -79,32 +81,25 @@ public class FileUploadRepository {
|
|||||||
.run(connection);
|
.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> getAllExpiredFileUploads() {
|
||||||
public List<FileUpload> findAllExpiredActiveFileUploads() {
|
long timestamp = getTimestamp24HoursAgo();
|
||||||
|
List<FileUpload> olderFiles = r.db("sharepulse").table("file_uploads")
|
||||||
long timestamp = getOneMinuteAgoTimestamp();
|
|
||||||
|
|
||||||
return r.db("sharepulse").table("file_uploads")
|
|
||||||
.filter(row -> row.g("uploadDate").lt(timestamp))
|
.filter(row -> row.g("uploadDate").lt(timestamp))
|
||||||
.run(connection, FileUpload.class)
|
.run(connection, FileUpload.class)
|
||||||
.toList();
|
.toList();
|
||||||
|
return olderFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FileUpload> findAll() {
|
private long getTimestamp24HoursAgo() {
|
||||||
return r.db("sharepulse").table("file_uploads")
|
Instant now = Instant.now();
|
||||||
.run(connection, FileUpload.class)
|
Instant oneMinuteAgo = now.minus(24, ChronoUnit.HOURS);
|
||||||
.toList();
|
return oneMinuteAgo.toEpochMilli();
|
||||||
}
|
}
|
||||||
|
|
||||||
private long get24HoursAgoTimestamp() {
|
// For testing only
|
||||||
Calendar calendar = Calendar.getInstance();
|
private long getTimestampOneMinuteAgo() {
|
||||||
calendar.add(Calendar.HOUR, -24);
|
Instant now = Instant.now();
|
||||||
return calendar.getTimeInMillis() / 1000;
|
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