refac: article reads, story delete, no leaks, stored SEO status, rate limit, cleanup (%site%, article repo split, old lang repos, one default per site rule to domain)
This commit is contained in:
1 parent
9d284e65a9
commit
7c15206170
85 files changed
+1788
-593
No files matched your search
@@ -0,0 +1,47 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
domain "RenewCMS/internal/domain/article"
|
||||
entity "RenewCMS/internal/infrastructure/persistence/models"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const (
|
||||
seoStatusColumn = "seo_status"
|
||||
seoSuggestionsColumn = "seo_suggestions"
|
||||
seoVersionColumn = "seo_version"
|
||||
)
|
||||
|
||||
func withStaleSEO(columns map[string]any) map[string]any {
|
||||
columns[seoStatusColumn] = ""
|
||||
columns[seoVersionColumn] = gorm.Expr(seoVersionColumn + " + 1")
|
||||
return columns
|
||||
}
|
||||
|
||||
func (a *ArticleRepository) StaleSEO(afterID uint32, limit int) ([]domain.Article, error) {
|
||||
var found []entity.Article
|
||||
err := a.db.Model(&entity.Article{}).Where(seoStatusColumn+" = ? AND id > ?", "", afterID).Order("id ASC").Limit(limit).Find(&found).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return a.withAuthors(a.db, toDomainArticles(found))
|
||||
}
|
||||
|
||||
func (a *ArticleRepository) StoreSEO(records []domain.SEORecord) error {
|
||||
return a.db.Transaction(func(tx *gorm.DB) error {
|
||||
for _, record := range records {
|
||||
stored := map[string]any{seoStatusColumn: record.Summary.Status, seoSuggestionsColumn: record.Summary.Suggestions}
|
||||
if err := tx.Model(&entity.Article{}).Where("id = ? AND "+seoVersionColumn+" = ?", record.ArticleID, record.Version).UpdateColumns(stored).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (a *ArticleRepository) MarkSiteSEOStale(siteID uint32) error {
|
||||
return a.db.Model(&entity.Article{}).Where("site_id = ?", siteID).UpdateColumns(withStaleSEO(map[string]any{})).Error
|
||||
}
|
||||
|
||||
var _ domain.SEOIndex = &ArticleRepository{}
|
||||
Reference in new issue
Block a user