diff --git a/backend/internal/assets/cacher/cacher.go b/backend/internal/assets/cacher/cacher.go index fd7fe1e70..619c28c7c 100644 --- a/backend/internal/assets/cacher/cacher.go +++ b/backend/internal/assets/cacher/cacher.go @@ -73,7 +73,8 @@ func (c *cacher) cacheURL(requestURL string, sessionID uint64, depth byte, urlCo return } c.timeoutMap.add(cachePath) - if c.s3.Exists(cachePath) { + crTime := c.s3.GetCreationTime(cachePath) + if crTime != nil && crTime.After(time.Now().Add(-MAX_STORAGE_TIME)) { // recently uploaded return } diff --git a/backend/pkg/storage/s3.go b/backend/pkg/storage/s3.go index 67ebaaf4f..2e97673d3 100644 --- a/backend/pkg/storage/s3.go +++ b/backend/pkg/storage/s3.go @@ -6,6 +6,7 @@ import ( "os" "sort" "strconv" + "time" _s3 "github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3/s3manager" @@ -71,6 +72,17 @@ func (s3 *S3) Exists(key string) bool { return false } +func (s3 *S3) GetCreationTime(key string) *time.Time { + ans, err := s3.svc.HeadObject(&_s3.HeadObjectInput{ + Bucket: s3.bucket, + Key: &key, + }) + if err != nil { + return nil + } + return ans.LastModified +} + const MAX_RETURNING_COUNT = 40 func (s3 *S3) GetFrequentlyUsedKeys(projectID uint64) ([]string, error) { diff --git a/backend/pkg/url/assets/url.go b/backend/pkg/url/assets/url.go index adb26e0aa..83cdd5ac1 100644 --- a/backend/pkg/url/assets/url.go +++ b/backend/pkg/url/assets/url.go @@ -14,7 +14,7 @@ func getSessionKey(sessionID uint64) string { return strconv.FormatUint( uint64(time.UnixMilli( int64(flakeid.ExtractTimestamp(sessionID)), - ).Weekday()), + ).Day()), 10, ) }