fix some endpoints
This commit is contained in:
parent
7aee99ac42
commit
6f1b94c040
10 changed files with 47 additions and 41 deletions
|
@ -4,9 +4,14 @@
|
|||
|
||||
create table account_follows (
|
||||
account_id text not null references accounts (id) on delete cascade,
|
||||
blog_id text not null references blogs (id) on delete cascade
|
||||
blog_id text not null references blogs (id) on delete cascade,
|
||||
|
||||
primary key (account_id, blog_id)
|
||||
);
|
||||
|
||||
create index account_follows_account_id_idx on account_follows (account_id);
|
||||
|
||||
-- +migrate Down
|
||||
|
||||
drop index account_follows_account_id_idx;
|
||||
drop table account_follows;
|
||||
|
|
|
@ -19,22 +19,26 @@ func NewTimelineStore(q Querier) *TimelineStore {
|
|||
}
|
||||
|
||||
type TimelinePost struct {
|
||||
database.Post
|
||||
database.Blog
|
||||
Post database.Post `db:"p"`
|
||||
Blog database.Blog `db:"b"`
|
||||
Account database.Account `db:"a"`
|
||||
}
|
||||
|
||||
func (s *TimelineStore) Home(ctx context.Context, accountID ulid.ULID, limit int, before, after *ulid.ULID) ([]TimelinePost, error) {
|
||||
q := sqlf.Sprintf("SELECT p.*, b.account_id, b.name, b.domain FROM posts p JOIN blogs b ON b.id = p.blog_id")
|
||||
q := sqlf.Sprintf(`SELECT p.id as "p.id", p.blog_id as "p.blog_id", p.content as "p.content", p.source as "p.source", p.visibility as "p.visibility",
|
||||
b.id as "b.id", b.name as "b.name", b.domain as "b.domain", b.bio as "b.bio", b.account_id as "b.account_id",
|
||||
a.id as "a.id", a.username as "a.username", a.domain as "a.domain"
|
||||
FROM posts p JOIN blogs b ON b.id = p.blog_id JOIN accounts a on a.id = b.account_id`)
|
||||
|
||||
q = sqlf.Sprintf("%v WHERE (blog_id IN (%s) OR blog_id IN (%s))", q,
|
||||
sqlf.Sprintf("SELECT id FROM blogs WHERE account_id = %s", accountID),
|
||||
sqlf.Sprintf("SELECT blog_id FROM account_follows WHERE account_id = %s", accountID))
|
||||
|
||||
if before != nil {
|
||||
q = sqlf.Sprintf("%v AND id < %s", q, *before)
|
||||
q = sqlf.Sprintf("%v AND p.id < %s", q, *before)
|
||||
}
|
||||
if after != nil {
|
||||
q = sqlf.Sprintf("%v AND id > %s", q, *after)
|
||||
q = sqlf.Sprintf("%v AND p.id > %s", q, *after)
|
||||
}
|
||||
|
||||
q = sqlf.Sprintf("%v AND (visibility != %s OR (b.account_id = %s OR %s IN (%s)))", q, database.DirectVisibility, accountID, accountID,
|
||||
|
@ -43,7 +47,7 @@ func (s *TimelineStore) Home(ctx context.Context, accountID ulid.ULID, limit int
|
|||
if limit <= 0 || limit > 100 {
|
||||
limit = 100
|
||||
}
|
||||
q = sqlf.Sprintf("%v ORDER BY id DESC LIMIT %d", q, limit)
|
||||
q = sqlf.Sprintf("%v ORDER BY p.id DESC LIMIT %d", q, limit)
|
||||
|
||||
return Select[TimelinePost](ctx, s.q, q)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue