fix(backend/assets): once-a-day versioning; once-a-day re-uploading (#699)
This commit is contained in:
parent
37e3e33c7d
commit
f699b03117
3 changed files with 15 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ func getSessionKey(sessionID uint64) string {
|
|||
return strconv.FormatUint(
|
||||
uint64(time.UnixMilli(
|
||||
int64(flakeid.ExtractTimestamp(sessionID)),
|
||||
).Weekday()),
|
||||
).Day()),
|
||||
10,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue