mirror of
https://github.com/Kugelschieber/marvinblum.git
synced 2026-01-18 06:40:27 +00:00
Better blog article caching.
This commit is contained in:
28
blog/blog.go
28
blog/blog.go
@@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
blogCacheTime = time.Hour
|
blogCacheTime = time.Minute * 15
|
||||||
blogFileCache = "static/blog"
|
blogFileCache = "static/blog"
|
||||||
maxLatestArticles = 3
|
maxLatestArticles = 3
|
||||||
)
|
)
|
||||||
@@ -115,17 +115,27 @@ func (blog *Blog) loadArticles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (blog *Blog) loadArticle(article emvi.Article) *emvi.ArticleContent {
|
func (blog *Blog) loadArticle(article emvi.Article) *emvi.ArticleContent {
|
||||||
_, content, _, err := blog.client.GetArticle(article.Id, article.LatestArticleContent.LanguageId, 0)
|
existingArticle := blog.articles[article.Id]
|
||||||
|
var content *emvi.ArticleContent
|
||||||
|
|
||||||
if err != nil {
|
if len(existingArticle.Id) == 0 || !existingArticle.ModTime.Equal(article.ModTime) {
|
||||||
logbuch.Error("Error loading article", logbuch.Fields{"err": err, "id": article.Id})
|
var err error
|
||||||
return nil
|
_, content, _, err = blog.client.GetArticle(article.Id, article.LatestArticleContent.LanguageId, 0)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logbuch.Error("Error loading article", logbuch.Fields{"err": err, "id": article.Id})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
blog.downloadAttachments(article.Id, content.Content)
|
||||||
|
content.Content = linkRegex.ReplaceAllString(content.Content, `href="/blog/$1"`)
|
||||||
|
content.Content = attachmentRegex.ReplaceAllString(content.Content, fmt.Sprintf(`$1="/static/blog/%s/$3"`, article.Id))
|
||||||
|
logbuch.Debug("Article loaded", logbuch.Fields{"id": article.Id})
|
||||||
|
} else {
|
||||||
|
content = existingArticle.LatestArticleContent
|
||||||
|
logbuch.Debug("Article up to date, skipping refreshing cache", logbuch.Fields{"id": article.Id})
|
||||||
}
|
}
|
||||||
|
|
||||||
blog.downloadAttachments(article.Id, content.Content)
|
|
||||||
content.Content = linkRegex.ReplaceAllString(content.Content, `href="/blog/$1"`)
|
|
||||||
content.Content = attachmentRegex.ReplaceAllString(content.Content, fmt.Sprintf(`$1="/static/blog/%s/$3"`, article.Id))
|
|
||||||
logbuch.Debug("Article loaded", logbuch.Fields{"id": article.Id})
|
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user