2017-11-10 03:33:11 +00:00
|
|
|
package common
|
2017-11-06 07:44:08 +00:00
|
|
|
|
2019-05-17 08:40:41 +00:00
|
|
|
//import "log"
|
2020-01-02 21:52:41 +00:00
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
|
|
|
)
|
2017-11-06 07:44:08 +00:00
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
var Rstore ReplyStore
|
2017-11-06 07:44:08 +00:00
|
|
|
|
|
|
|
type ReplyStore interface {
|
|
|
|
Get(id int) (*Reply, error)
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
Each(f func(*Reply) error) error
|
|
|
|
Exists(id int) bool
|
2020-02-05 02:48:35 +00:00
|
|
|
Create(t *Topic, content, ip string, uid int) (id int, err error)
|
2019-06-01 12:31:48 +00:00
|
|
|
Count() (count int)
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
CountUser(uid int) (count int)
|
|
|
|
CountMegaUser(uid int) (count int)
|
|
|
|
CountBigUser(uid int) (count int)
|
2019-05-17 08:40:41 +00:00
|
|
|
|
|
|
|
SetCache(cache ReplyCache)
|
|
|
|
GetCache() ReplyCache
|
2017-11-06 07:44:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type SQLReplyStore struct {
|
2019-05-17 08:40:41 +00:00
|
|
|
cache ReplyCache
|
|
|
|
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
get *sql.Stmt
|
|
|
|
getAll *sql.Stmt
|
|
|
|
exists *sql.Stmt
|
|
|
|
create *sql.Stmt
|
|
|
|
count *sql.Stmt
|
|
|
|
countUser *sql.Stmt
|
|
|
|
countWordUser *sql.Stmt
|
2017-11-06 07:44:08 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 08:40:41 +00:00
|
|
|
func NewSQLReplyStore(acc *qgen.Accumulator, cache ReplyCache) (*SQLReplyStore, error) {
|
|
|
|
if cache == nil {
|
|
|
|
cache = NewNullReplyCache()
|
|
|
|
}
|
2019-11-12 06:56:51 +00:00
|
|
|
re := "replies"
|
2017-11-06 07:44:08 +00:00
|
|
|
return &SQLReplyStore{
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
cache: cache,
|
|
|
|
get: acc.Select(re).Columns("tid, content, createdBy, createdAt, lastEdit, lastEditBy, ip, likeCount, attachCount, actionType").Where("rid=?").Prepare(),
|
|
|
|
getAll: acc.Select(re).Columns("rid,tid, content, createdBy, createdAt, lastEdit, lastEditBy, ip, likeCount, attachCount, actionType").Prepare(),
|
|
|
|
exists: acc.Exists(re, "rid").Prepare(),
|
|
|
|
create: acc.Insert(re).Columns("tid, content, parsed_content, createdAt, lastUpdated, ip, words, createdBy").Fields("?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?").Prepare(),
|
|
|
|
count: acc.Count(re).Prepare(),
|
|
|
|
countUser: acc.Count(re).Where("createdBy=?").Prepare(),
|
|
|
|
countWordUser: acc.Count(re).Where("createdBy=? AND words>=?").Prepare(),
|
2017-11-06 16:24:45 +00:00
|
|
|
}, acc.FirstError()
|
2017-11-06 07:44:08 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 08:40:41 +00:00
|
|
|
func (s *SQLReplyStore) Get(id int) (*Reply, error) {
|
2019-06-01 12:31:48 +00:00
|
|
|
r, err := s.cache.Get(id)
|
2019-05-17 08:40:41 +00:00
|
|
|
if err == nil {
|
2019-06-01 12:31:48 +00:00
|
|
|
return r, nil
|
2019-05-17 08:40:41 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 12:31:48 +00:00
|
|
|
r = &Reply{ID: id}
|
2019-08-31 22:34:43 +00:00
|
|
|
err = s.get.QueryRow(id).Scan(&r.ParentID, &r.Content, &r.CreatedBy, &r.CreatedAt, &r.LastEdit, &r.LastEditBy, &r.IP, &r.LikeCount, &r.AttachCount, &r.ActionType)
|
2019-05-17 08:40:41 +00:00
|
|
|
if err == nil {
|
2019-06-01 12:31:48 +00:00
|
|
|
_ = s.cache.Set(r)
|
2019-05-17 08:40:41 +00:00
|
|
|
}
|
2019-06-01 12:31:48 +00:00
|
|
|
return r, err
|
2017-11-06 07:44:08 +00:00
|
|
|
}
|
|
|
|
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
/*func (s *SQLReplyStore) eachr(f func(*sql.Rows) error) error {
|
|
|
|
return eachall(s.getAll, f)
|
|
|
|
}*/
|
|
|
|
|
|
|
|
func (s *SQLReplyStore) Each(f func(*Reply) error) error {
|
|
|
|
rows, err := s.getAll.Query()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
for rows.Next() {
|
|
|
|
r := new(Reply)
|
|
|
|
if err := rows.Scan(&r.ID, &r.ParentID, &r.Content, &r.CreatedBy, &r.CreatedAt, &r.LastEdit, &r.LastEditBy, &r.IP, &r.LikeCount, &r.AttachCount, &r.ActionType); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := f(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rows.Err()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SQLReplyStore) Exists(id int) bool {
|
|
|
|
err := s.exists.QueryRow(id).Scan(&id)
|
|
|
|
if err != nil && err != ErrNoRows {
|
|
|
|
LogError(err)
|
|
|
|
}
|
|
|
|
return err != ErrNoRows
|
|
|
|
}
|
|
|
|
|
2017-11-06 07:44:08 +00:00
|
|
|
// TODO: Write a test for this
|
2020-02-26 10:34:38 +00:00
|
|
|
func (s *SQLReplyStore) Create(t *Topic, content, ip string, uid int) (id int, err error) {
|
2020-01-02 21:52:41 +00:00
|
|
|
if Config.DisablePostIP {
|
2020-02-04 11:47:03 +00:00
|
|
|
ip = ""
|
2020-01-02 21:52:41 +00:00
|
|
|
}
|
2020-02-04 11:47:03 +00:00
|
|
|
res, err := s.create.Exec(t.ID, content, ParseMessage(content, t.ParentID, "forums", nil, nil), ip, WordCount(content), uid)
|
2017-11-06 07:44:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2017-11-08 07:28:33 +00:00
|
|
|
|
2017-11-06 07:44:08 +00:00
|
|
|
lastID, err := res.LastInsertId()
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2020-02-26 10:34:38 +00:00
|
|
|
id = int(lastID)
|
|
|
|
return id, t.AddReply(id, uid)
|
2017-11-06 07:44:08 +00:00
|
|
|
}
|
2019-05-17 08:40:41 +00:00
|
|
|
|
2019-06-01 12:31:48 +00:00
|
|
|
// TODO: Write a test for this
|
|
|
|
// Count returns the total number of topic replies on these forums
|
|
|
|
func (s *SQLReplyStore) Count() (count int) {
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
return Countf(s.count)
|
|
|
|
}
|
|
|
|
func (s *SQLReplyStore) CountUser(uid int) (count int) {
|
|
|
|
return Countf(s.countUser, uid)
|
|
|
|
}
|
|
|
|
func (s *SQLReplyStore) CountMegaUser(uid int) (count int) {
|
|
|
|
return Countf(s.countWordUser, uid, SettingBox.Load().(SettingMap)["megapost_min_words"].(int))
|
|
|
|
}
|
|
|
|
func (s *SQLReplyStore) CountBigUser(uid int) (count int) {
|
|
|
|
return Countf(s.countWordUser, uid, SettingBox.Load().(SettingMap)["bigpost_min_words"].(int))
|
2019-06-01 12:31:48 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 08:40:41 +00:00
|
|
|
func (s *SQLReplyStore) SetCache(cache ReplyCache) {
|
|
|
|
s.cache = cache
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SQLReplyStore) GetCache() ReplyCache {
|
|
|
|
return s.cache
|
|
|
|
}
|