Skip to content

Commit

Permalink
improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxiaohei committed Feb 22, 2014
1 parent a18cbeb commit ff41f13
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/model/content.go
Expand Up @@ -24,6 +24,8 @@ type Content struct {
Title string
Slug string
Text string
// Rendered string
textRendered string
//Category string
Tags []string

Expand Down Expand Up @@ -84,7 +86,10 @@ func (cnt *Content) Link() string {
func (cnt *Content) Content() string {
txt := strings.Replace(cnt.Text, "<!--more-->", "", -1)
if GetSetting("enable_go_markdown") == "true" {
return utils.Markdown2Html(txt)
if cnt.textRendered == ""{
cnt.textRendered = utils.Markdown2Html(txt)
}
return cnt.textRendered
}
return txt
}
Expand Down Expand Up @@ -225,6 +230,7 @@ func CreateContent(c *Content, t string) (*Content, error) {
c.Comments = make([]*Comment, 0)
c.Type = t
c.Hits = 1
c.textRendered = ""
contents[c.Id] = c
contentsIndex[c.Type] = append([]int{c.Id}, contentsIndex[c.Type]...)
generatePublishArticleIndex()
Expand All @@ -236,6 +242,8 @@ func CreateContent(c *Content, t string) (*Content, error) {
// It will re-generate related indexes.
func SaveContent(c *Content) {
c.EditTime = utils.Now()
// clean rendered cache text
c.textRendered = ""
generatePublishArticleIndex()
go SyncContent(c)
}
Expand Down

0 comments on commit ff41f13

Please sign in to comment.