2021-04-28 08:39:08 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2022-02-21 03:53:13 +00:00
|
|
|
"database/sql"
|
2021-04-28 08:39:08 +00:00
|
|
|
|
2022-02-21 03:53:13 +00:00
|
|
|
qgen "git.tuxpa.in/a/gosora/query_gen"
|
2021-04-28 08:39:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var ActivityMatches ActivityStreamMatches
|
|
|
|
|
|
|
|
type ActivityStreamMatches interface {
|
2022-02-21 03:32:53 +00:00
|
|
|
Add(watcher, asid int) error
|
|
|
|
Delete(watcher, asid int) error
|
|
|
|
DeleteAndCountChanged(watcher, asid int) (int, error)
|
|
|
|
CountAsid(asid int) int
|
2021-04-28 08:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type DefaultActivityStreamMatches struct {
|
2022-02-21 03:32:53 +00:00
|
|
|
add *sql.Stmt
|
|
|
|
delete *sql.Stmt
|
|
|
|
countAsid *sql.Stmt
|
2021-04-28 08:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewDefaultActivityStreamMatches(acc *qgen.Accumulator) (*DefaultActivityStreamMatches, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
asm := "activity_stream_matches"
|
|
|
|
return &DefaultActivityStreamMatches{
|
|
|
|
add: acc.Insert(asm).Columns("watcher,asid").Fields("?,?").Prepare(),
|
|
|
|
delete: acc.Delete(asm).Where("watcher=? AND asid=?").Prepare(),
|
|
|
|
countAsid: acc.Count(asm).Where("asid=?").Prepare(),
|
|
|
|
}, acc.FirstError()
|
2021-04-28 08:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DefaultActivityStreamMatches) Add(watcher, asid int) error {
|
2022-02-21 03:32:53 +00:00
|
|
|
_, e := s.add.Exec(watcher, asid)
|
|
|
|
return e
|
2021-04-28 08:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DefaultActivityStreamMatches) Delete(watcher, asid int) error {
|
2022-02-21 03:32:53 +00:00
|
|
|
_, e := s.delete.Exec(watcher, asid)
|
|
|
|
return e
|
2021-04-28 08:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DefaultActivityStreamMatches) DeleteAndCountChanged(watcher, asid int) (int, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
res, e := s.delete.Exec(watcher, asid)
|
|
|
|
if e != nil {
|
|
|
|
return 0, e
|
|
|
|
}
|
|
|
|
c64, e := res.RowsAffected()
|
|
|
|
return int(c64), e
|
2021-04-28 08:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DefaultActivityStreamMatches) CountAsid(asid int) int {
|
2022-02-21 03:32:53 +00:00
|
|
|
return Countf(s.countAsid, asid)
|
2021-04-28 08:39:08 +00:00
|
|
|
}
|