satisfies memo.Func
()
| 68 | |
| 69 | // satisfies memo.Func |
| 70 | func (app *App) FetchPublicPosts() (interface{}, error) { |
| 71 | // Conditions |
| 72 | limit := fmt.Sprintf("LIMIT %d", tlMaxPostCache) |
| 73 | // This is better than the hard limit when limiting posts from individual authors |
| 74 | // ageCond := `p.created >= ` + app.db.dateSub(3, "month") + ` AND ` |
| 75 | |
| 76 | // Finds all public posts and posts in a public collection published during the owner's active subscription period and within the last 3 months |
| 77 | rows, err := app.db.Query(`SELECT p.id, c.id, alias, c.title, p.slug, p.title, p.content, p.text_appearance, p.language, p.rtl, p.created, p.updated |
| 78 | FROM collections c |
| 79 | LEFT JOIN posts p ON p.collection_id = c.id |
| 80 | LEFT JOIN users u ON u.id = p.owner_id |
| 81 | WHERE c.privacy = 1 AND (p.created <= ` + app.db.now() + ` AND pinned_position IS NULL) AND u.status = 0 |
| 82 | ORDER BY p.created DESC |
| 83 | ` + limit) |
| 84 | if err != nil { |
| 85 | log.Error("Failed selecting from posts: %v", err) |
| 86 | return nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't retrieve collection posts." + err.Error()} |
| 87 | } |
| 88 | defer rows.Close() |
| 89 | |
| 90 | ap := map[string]uint{} |
| 91 | |
| 92 | posts := []PublicPost{} |
| 93 | for rows.Next() { |
| 94 | p := &Post{} |
| 95 | c := &Collection{} |
| 96 | var alias, title sql.NullString |
| 97 | err = rows.Scan(&p.ID, &c.ID, &alias, &title, &p.Slug, &p.Title, &p.Content, &p.Font, &p.Language, &p.RTL, &p.Created, &p.Updated) |
| 98 | if err != nil { |
| 99 | log.Error("[READ] Unable to scan row, skipping: %v", err) |
| 100 | continue |
| 101 | } |
| 102 | c.hostName = app.cfg.App.Host |
| 103 | |
| 104 | isCollectionPost := alias.Valid |
| 105 | if isCollectionPost { |
| 106 | c.Alias = alias.String |
| 107 | if c.Alias != "" && ap[c.Alias] == tlMaxAuthorPosts { |
| 108 | // Don't add post if we've hit the post-per-author limit |
| 109 | continue |
| 110 | } |
| 111 | |
| 112 | c.Public = true |
| 113 | c.Title = title.String |
| 114 | c.Monetization = app.db.GetCollectionAttribute(c.ID, "monetization_pointer") |
| 115 | } |
| 116 | |
| 117 | p.extractData() |
| 118 | p.handlePremiumContent(c, false, false, app.cfg) |
| 119 | p.HTMLContent = template.HTML(applyMarkdown([]byte(p.Content), "", app.cfg)) |
| 120 | fp := p.processPost() |
| 121 | if isCollectionPost { |
| 122 | fp.Collection = &CollectionObj{Collection: *c} |
| 123 | } |
| 124 | |
| 125 | posts = append(posts, fp) |
| 126 | ap[c.Alias]++ |
| 127 | } |
nothing calls this directly
no test coverage detected