c60118e7c4
Add Http Conn Count tracking. Move more panel phrases into the panel namespace. Use a string builder in hookgen. Use Countf() in a couple of places to eliminate boilerplate. Reduce prepared stmt boilerplate in forum store with a lambda. Reduce prepared stmt boilerplate in topic.go with a lambda. Reduce prepared stmt boilerplate in group.go with a lambda. Add TestSetCreatedAt method to *Topic. Add DateOlderThanQ method to *accDeleteBuilder and *accUpdateBuilder. Add Stmt method to *accUpdateBuilder and *AccSelectBuilder. Add AccBuilder interface. Shorten variable names. Shorten extractPerm name to ep. Add avatar_visibility setting stub. Implementation coming in a later commit. Don't set an IP for installer generated posts. Add counters_perf_tick_row hook. Add avatar_visibility phrase. Add avatar_visibility_label phrase. Rename forums_no_description to forums_no_desc. Rename panel.forums_create_description_label to panel.forums_create_desc_label. Rename panel.forums_create_description to panel.forums_create_desc. Rename panel_forum_description to panel.forum_desc. Rename panel_forum_description_placeholder to panel.forum_desc_placeholder. Add panel_debug_http_conns_label phrase. Add panel.forum_actions_head phrase. Add panel.forum_actions_create_head phrase. Add panel.forum_action_run_on_topic_creation phrase. Add panel.forum_action_run_days_after_topic_creation phrase. Add panel.forum_action_run_days_after_topic_last_reply phrase. Add panel.forum_action_action phrase. Add panel.forum_action_action_delete phrase. Add panel.forum_action_action_lock phrase. Add panel.forum_action_action_unlock phrase. Add panel.forum_action_action_move phrase. Add panel.forum_action_extra phrase. Add panel.forum_action_create_button phrase. You will need to run the patcher / updater for this commit.
118 lines
3.8 KiB
Go
118 lines
3.8 KiB
Go
package common
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
|
)
|
|
|
|
var Activity ActivityStream
|
|
|
|
type ActivityStream interface {
|
|
Add(a Alert) (int, error)
|
|
Get(id int) (Alert, error)
|
|
Delete(id int) error
|
|
DeleteByParams(event string, targetID int, targetType string) error
|
|
DeleteByParamsExtra(event string, targetID int, targetType, extra string) error
|
|
AidsByParams(event string, elementID int, elementType string) (aids []int, err error)
|
|
AidsByParamsExtra(event string, elementID int, elementType, extra string) (aids []int, err error)
|
|
Count() (count int)
|
|
}
|
|
|
|
type DefaultActivityStream struct {
|
|
add *sql.Stmt
|
|
get *sql.Stmt
|
|
delete *sql.Stmt
|
|
deleteByParams *sql.Stmt
|
|
deleteByParamsExtra *sql.Stmt
|
|
aidsByParams *sql.Stmt
|
|
aidsByParamsExtra *sql.Stmt
|
|
count *sql.Stmt
|
|
}
|
|
|
|
func NewDefaultActivityStream(acc *qgen.Accumulator) (*DefaultActivityStream, error) {
|
|
as := "activity_stream"
|
|
return &DefaultActivityStream{
|
|
add: acc.Insert(as).Columns("actor,targetUser,event,elementType,elementID,createdAt,extra").Fields("?,?,?,?,?,UTC_TIMESTAMP(),?").Prepare(),
|
|
get: acc.Select(as).Columns("actor,targetUser,event,elementType,elementID,createdAt,extra").Where("asid=?").Prepare(),
|
|
delete: acc.Delete(as).Where("asid=?").Prepare(),
|
|
deleteByParams: acc.Delete(as).Where("event=? AND elementID=? AND elementType=?").Prepare(),
|
|
deleteByParamsExtra: acc.Delete(as).Where("event=? AND elementID=? AND elementType=? AND extra=?").Prepare(),
|
|
aidsByParams: acc.Select(as).Columns("asid").Where("event=? AND elementID=? AND elementType=?").Prepare(),
|
|
aidsByParamsExtra: acc.Select(as).Columns("asid").Where("event=? AND elementID=? AND elementType=? AND extra=?").Prepare(),
|
|
count: acc.Count(as).Prepare(),
|
|
}, acc.FirstError()
|
|
}
|
|
|
|
func (s *DefaultActivityStream) Add(a Alert) (int, error) {
|
|
res, err := s.add.Exec(a.ActorID, a.TargetUserID, a.Event, a.ElementType, a.ElementID, a.Extra)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
lastID, err := res.LastInsertId()
|
|
return int(lastID), err
|
|
}
|
|
|
|
func (s *DefaultActivityStream) Get(id int) (Alert, error) {
|
|
a := Alert{ASID: id}
|
|
err := s.get.QueryRow(id).Scan(&a.ActorID, &a.TargetUserID, &a.Event, &a.ElementType, &a.ElementID, &a.CreatedAt, &a.Extra)
|
|
return a, err
|
|
}
|
|
|
|
func (s *DefaultActivityStream) Delete(id int) error {
|
|
_, err := s.delete.Exec(id)
|
|
return err
|
|
}
|
|
|
|
func (s *DefaultActivityStream) DeleteByParams(event string, elementID int, elementType string) error {
|
|
_, err := s.deleteByParams.Exec(event, elementID, elementType)
|
|
return err
|
|
}
|
|
|
|
func (s *DefaultActivityStream) DeleteByParamsExtra(event string, elementID int, elementType, extra string) error {
|
|
_, err := s.deleteByParamsExtra.Exec(event, elementID, elementType, extra)
|
|
return err
|
|
}
|
|
|
|
func (s *DefaultActivityStream) AidsByParams(event string, elementID int, elementType string) (aids []int, err error) {
|
|
rows, err := s.aidsByParams.Query(event, elementID, elementType)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
for rows.Next() {
|
|
var aid int
|
|
if err := rows.Scan(&aid); err != nil {
|
|
return nil, err
|
|
}
|
|
aids = append(aids, aid)
|
|
}
|
|
return aids, rows.Err()
|
|
}
|
|
|
|
func (s *DefaultActivityStream) AidsByParamsExtra(event string, elementID int, elementType, extra string) (aids []int, e error) {
|
|
rows, e := s.aidsByParamsExtra.Query(event, elementID, elementType, extra)
|
|
if e != nil {
|
|
return nil, e
|
|
}
|
|
defer rows.Close()
|
|
for rows.Next() {
|
|
var aid int
|
|
if e := rows.Scan(&aid); e != nil {
|
|
return nil, e
|
|
}
|
|
aids = append(aids, aid)
|
|
}
|
|
return aids, rows.Err()
|
|
}
|
|
|
|
// TODO: Write a test for this
|
|
// Count returns the total number of activity stream items
|
|
func (s *DefaultActivityStream) Count() (count int) {
|
|
e := s.count.QueryRow().Scan(&count)
|
|
if e != nil {
|
|
LogError(e)
|
|
}
|
|
return count
|
|
}
|