saving 25ms-50ms + move summary column
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// TODO docstring
|
||||
type Article struct {
|
||||
Id int
|
||||
SourceUrl string
|
||||
@@ -13,7 +12,6 @@ type Article struct {
|
||||
FetchDate time.Time
|
||||
Title string
|
||||
Content string
|
||||
AiSummary string
|
||||
}
|
||||
|
||||
func (a *Article) Clone() *Article {
|
||||
@@ -24,11 +22,9 @@ func (a *Article) Clone() *Article {
|
||||
FetchDate: a.FetchDate,
|
||||
Title: a.Title,
|
||||
Content: a.Content,
|
||||
AiSummary: a.AiSummary,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO docstring
|
||||
type ArticleViewModel struct {
|
||||
Id int
|
||||
Title string
|
||||
@@ -49,13 +45,11 @@ type ArticlePageViewModel struct {
|
||||
|
||||
// TODO docstring
|
||||
func (a *Article) ViewModel() *ArticleViewModel {
|
||||
summary := a.AiSummary
|
||||
if summary == "" {
|
||||
if len(a.Content) > 200 {
|
||||
summary = a.Content[:200]
|
||||
} else {
|
||||
summary = a.Content
|
||||
}
|
||||
var summary string
|
||||
if len(a.Content) > 200 {
|
||||
summary = a.Content[:200]
|
||||
} else {
|
||||
summary = a.Content
|
||||
}
|
||||
|
||||
short_url := ""
|
||||
@@ -70,15 +64,11 @@ func (a *Article) ViewModel() *ArticleViewModel {
|
||||
PublishDate: a.PublishDate.Local().Format("02.01.2006"),
|
||||
ShortSource: short_url,
|
||||
Summary: summary,
|
||||
AiSummarized: a.AiSummary != "",
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Article) PageViewModel() *ArticlePageViewModel {
|
||||
summary := a.AiSummary
|
||||
if summary == "" {
|
||||
summary = "N/A"
|
||||
}
|
||||
summary := "N/A"
|
||||
|
||||
short_url := ""
|
||||
parsedURL, err := url.Parse(a.SourceUrl)
|
||||
|
||||
Reference in New Issue
Block a user