fix(backend/assets): once-a-day versioning; once-a-day re-uploading (#699)

This commit is contained in:
Alex K 2022-09-01 10:52:13 +02:00 committed by GitHub
parent 37e3e33c7d
commit f699b03117
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View file

@ -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
}

View file

@ -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) {

View file

@ -14,7 +14,7 @@ func getSessionKey(sessionID uint64) string {
return strconv.FormatUint(
uint64(time.UnixMilli(
int64(flakeid.ExtractTimestamp(sessionID)),
).Weekday()),
).Day()),
10,
)
}