Browse Source

ref: load notes and articles separately

master
Inhji Y. 10 months ago
parent
commit
e7aad72e4c
  1. 11
      apps/blog/lib/blog.ex
  2. 4
      apps/tomie_web/lib/tomie_web/controllers/home_controller.ex

11
apps/blog/lib/blog.ex

@ -26,14 +26,25 @@ defmodule Blog do
Db.Repo.get!(Post, id)
|> Db.Repo.preload(@preloads)
def list_posts(limit \\ 10) do
Post
|> where(type: "post")
|> where([p], is_nil(p.title))
|> limit(^limit)
|> Db.Repo.all()
|> Db.Repo.preload(@preloads)
end
def list_articles(limit \\ 10) do
Post
|> where(type: "post")
|> where([p], not is_nil(p.title))
|> limit(^limit)
|> Db.Repo.all()
|> Db.Repo.preload(@preloads)
end
def delete_post(post) do
Db.Repo.delete(post)
end

4
apps/tomie_web/lib/tomie_web/controllers/home_controller.ex

@ -10,7 +10,8 @@ defmodule TomieWeb.HomeController do
def index(conn, _params) do
bookmarks = Bookmarks.list_bookmarks("", "recent", 3)
posts = Blog.list_posts(3)
posts = Blog.list_posts(1)
articles = Blog.list_articles(3)
listens = Listens.Listens.list_listens(3)
user = Tomie.Users.get_user!(1)
@ -18,6 +19,7 @@ defmodule TomieWeb.HomeController do
|> render("index.html",
bookmarks: bookmarks,
posts: posts,
articles: articles,
listens: listens,
page_title: "Home",
user: user

Loading…
Cancel
Save