⚡ Save post insight result in database
This commit is contained in:
@ -7,15 +7,18 @@ import (
|
||||
"time"
|
||||
|
||||
iproto "git.solsynth.dev/hypernet/insight/pkg/proto"
|
||||
"git.solsynth.dev/hypernet/interactive/pkg/internal/database"
|
||||
"git.solsynth.dev/hypernet/interactive/pkg/internal/gap"
|
||||
"git.solsynth.dev/hypernet/interactive/pkg/internal/models"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func GetPostInsightCacheKey(postId uint) string {
|
||||
return fmt.Sprintf("post-insight-%d", postId)
|
||||
}
|
||||
|
||||
func GeneratePostInsights(post models.Post, user uint) (string, error) {
|
||||
var insight models.PostInsight
|
||||
if err := database.C.Where("post_id = ?", post.ID).First(&insight).Error; err == nil {
|
||||
return insight.Response, nil
|
||||
}
|
||||
|
||||
var compactBuilder []string
|
||||
if val, ok := post.Body["title"].(string); ok && len(val) > 0 {
|
||||
compactBuilder = append(compactBuilder, "Title: "+val)
|
||||
@ -44,5 +47,14 @@ func GeneratePostInsights(post models.Post, user uint) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
insight = models.PostInsight{
|
||||
Response: resp.Response,
|
||||
Post: post,
|
||||
PostID: post.ID,
|
||||
}
|
||||
if err := database.C.Create(&insight).Error; err != nil {
|
||||
log.Error().Err(err).Msg("Failed to create post insight result in database...")
|
||||
}
|
||||
|
||||
return resp.Response, nil
|
||||
}
|
||||
|
@ -558,6 +558,9 @@ func DeletePost(item models.Post) error {
|
||||
}),
|
||||
UserId: lo.ToPtr(uint64(*item.Publisher.AccountID)),
|
||||
})
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("An error occurred when deleting post attachment...")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user