mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
rewrite items sql queries
This commit is contained in:
parent
077715f6c2
commit
d308bb64c2
@ -110,7 +110,7 @@ func listQueryPredicate(filter ItemFilter) (string, []interface{}) {
|
|||||||
cond := make([]string, 0)
|
cond := make([]string, 0)
|
||||||
args := make([]interface{}, 0)
|
args := make([]interface{}, 0)
|
||||||
if filter.FolderID != nil {
|
if filter.FolderID != nil {
|
||||||
cond = append(cond, "f.folder_id = ?")
|
cond = append(cond, "i.feed_id in (select id from feeds where folder_id = ?)")
|
||||||
args = append(args, *filter.FolderID)
|
args = append(args, *filter.FolderID)
|
||||||
}
|
}
|
||||||
if filter.FeedID != nil {
|
if filter.FeedID != nil {
|
||||||
@ -155,7 +155,6 @@ func (s *Storage) ListItems(filter ItemFilter, offset, limit int, newestFirst bo
|
|||||||
i.title, i.link, i.date,
|
i.title, i.link, i.date,
|
||||||
i.status, i.image, i.podcast_url
|
i.status, i.image, i.podcast_url
|
||||||
from items i
|
from items i
|
||||||
join feeds f on f.id = i.feed_id
|
|
||||||
where %s
|
where %s
|
||||||
order by %s
|
order by %s
|
||||||
limit %d offset %d
|
limit %d offset %d
|
||||||
@ -205,7 +204,6 @@ func (s *Storage) CountItems(filter ItemFilter) int64 {
|
|||||||
query := fmt.Sprintf(`
|
query := fmt.Sprintf(`
|
||||||
select count(i.id)
|
select count(i.id)
|
||||||
from items i
|
from items i
|
||||||
join feeds f on f.id = i.feed_id
|
|
||||||
where %s`, predicate)
|
where %s`, predicate)
|
||||||
row := s.db.QueryRow(query, args...)
|
row := s.db.QueryRow(query, args...)
|
||||||
if row != nil {
|
if row != nil {
|
||||||
@ -222,28 +220,10 @@ func (s *Storage) UpdateItemStatus(item_id int64, status ItemStatus) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) MarkItemsRead(filter MarkFilter) bool {
|
func (s *Storage) MarkItemsRead(filter MarkFilter) bool {
|
||||||
cond := make([]string, 0)
|
predicate, args := listQueryPredicate(ItemFilter{FolderID: filter.FolderID, FeedID: filter.FeedID})
|
||||||
args := make([]interface{}, 0)
|
|
||||||
|
|
||||||
if filter.FolderID != nil {
|
|
||||||
cond = append(cond, "f.folder_id = ?")
|
|
||||||
args = append(args, *filter.FolderID)
|
|
||||||
}
|
|
||||||
if filter.FeedID != nil {
|
|
||||||
cond = append(cond, "i.feed_id = ?")
|
|
||||||
args = append(args, *filter.FeedID)
|
|
||||||
}
|
|
||||||
predicate := "1"
|
|
||||||
if len(cond) > 0 {
|
|
||||||
predicate = strings.Join(cond, " and ")
|
|
||||||
}
|
|
||||||
query := fmt.Sprintf(`
|
query := fmt.Sprintf(`
|
||||||
update items set status = %d
|
update items as i set status = %d
|
||||||
where id in (
|
where %s and i.status != %d
|
||||||
select i.id from items i
|
|
||||||
join feeds f on f.id = i.feed_id
|
|
||||||
where %s and i.status != %d
|
|
||||||
)
|
|
||||||
`, READ, predicate, STARRED)
|
`, READ, predicate, STARRED)
|
||||||
_, err := s.db.Exec(query, args...)
|
_, err := s.db.Exec(query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user