2 Commits
v2.0 ... v2.1

Author SHA1 Message Date
Moritz Marquardt
5ed8d0f129 Add clarification on cache & reduce default branch cache to 15 minutes 2021-11-24 19:09:37 +01:00
Moritz Marquardt
e5385be6da Fix iterator issue causing 100% CPU load 2021-11-24 19:08:34 +01:00
2 changed files with 6 additions and 4 deletions

View File

@@ -443,7 +443,8 @@ func setupCertificates() {
// clean up expired certs // clean up expired certs
now := time.Now() now := time.Now()
expiredCertCount := 0 expiredCertCount := 0
key, resBytes, err := keyDatabase.Items().Next() keyDatabaseIterator := keyDatabase.Items()
key, resBytes, err := keyDatabaseIterator.Next()
for err == nil { for err == nil {
if !bytes.Equal(key, MainDomainSuffix) { if !bytes.Equal(key, MainDomainSuffix) {
resGob := bytes.NewBuffer(resBytes) resGob := bytes.NewBuffer(resBytes)
@@ -464,7 +465,7 @@ func setupCertificates() {
} }
} }
} }
key, resBytes, err = keyDatabase.Items().Next() key, resBytes, err = keyDatabaseIterator.Next()
} }
log.Printf("Removed %d expired certificates from the database", expiredCertCount) log.Printf("Removed %d expired certificates from the database", expiredCertCount)

View File

@@ -293,13 +293,13 @@ func returnErrorPage(ctx *fasthttp.RequestCtx, code int) {
message += " - domain not specified in <code>.domains</code> file" message += " - domain not specified in <code>.domains</code> file"
} }
if code == fasthttp.StatusFailedDependency { if code == fasthttp.StatusFailedDependency {
message += " - owner, repo or branch doesn't exist" message += " - owner, repo or branch doesn't exist (if everything's set up correctly, wait up to 15 minutes for cache invalidation)"
} }
ctx.Response.SetBody(bytes.ReplaceAll(NotFoundPage, []byte("%status"), []byte(strconv.Itoa(code)+" "+message))) ctx.Response.SetBody(bytes.ReplaceAll(NotFoundPage, []byte("%status"), []byte(strconv.Itoa(code)+" "+message)))
} }
// BranchExistanceCacheTimeout specifies the timeout for the default branch cache. It can be quite long. // BranchExistanceCacheTimeout specifies the timeout for the default branch cache. It can be quite long.
var DefaultBranchCacheTimeout = 1*time.Hour var DefaultBranchCacheTimeout = 15*time.Minute
// BranchExistanceCacheTimeout specifies the timeout for the branch timestamp & existance cache. It should be shorter // BranchExistanceCacheTimeout specifies the timeout for the branch timestamp & existance cache. It should be shorter
// than FileCacheTimeout, as that gets invalidated if the branch timestamp has changed. That way, repo changes will be // than FileCacheTimeout, as that gets invalidated if the branch timestamp has changed. That way, repo changes will be
// picked up faster, while still allowing the content to be cached longer if nothing changes. // picked up faster, while still allowing the content to be cached longer if nothing changes.
@@ -317,6 +317,7 @@ var FileCacheTimeout = 5*time.Minute
// FileCacheSizeLimit limits the maximum file size that will be cached, and is set to 1 MB by default. // FileCacheSizeLimit limits the maximum file size that will be cached, and is set to 1 MB by default.
var FileCacheSizeLimit = 1024 * 1024 var FileCacheSizeLimit = 1024 * 1024
// fileResponseCache stores responses from the Gitea server // fileResponseCache stores responses from the Gitea server
// TODO: make this an MRU cache with a size limit
var fileResponseCache = mcache.New() var fileResponseCache = mcache.New()
type fileResponse struct { type fileResponse struct {
exists bool exists bool