2019-06-05 06:00:40 +00:00
|
|
|
package common
|
|
|
|
|
2019-10-19 10:33:59 +00:00
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
|
|
|
)
|
2019-06-05 06:00:40 +00:00
|
|
|
|
|
|
|
var Likes LikeStore
|
|
|
|
|
|
|
|
type LikeStore interface {
|
|
|
|
BulkExists(ids []int, sentBy int, targetType string) ([]int, 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
|
|
|
Delete(targetID int, targetType string) error
|
2019-06-05 06:00:40 +00:00
|
|
|
Count() (count int)
|
|
|
|
}
|
|
|
|
|
|
|
|
type DefaultLikeStore struct {
|
2020-04-10 01:32:02 +00:00
|
|
|
count *sql.Stmt
|
|
|
|
delete *sql.Stmt
|
|
|
|
singleExists *sql.Stmt
|
2019-06-05 06:00:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewDefaultLikeStore(acc *qgen.Accumulator) (*DefaultLikeStore, error) {
|
|
|
|
return &DefaultLikeStore{
|
2020-04-10 01:32:02 +00:00
|
|
|
count: acc.Count("likes").Prepare(),
|
|
|
|
delete: acc.Delete("likes").Where("targetItem=? AND targetType=?").Prepare(),
|
|
|
|
singleExists: acc.Select("likes").Columns("targetItem").Where("sentBy=? AND targetType=? AND targetItem=?").Prepare(),
|
2019-06-05 06:00:40 +00:00
|
|
|
}, acc.FirstError()
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Write a test for this
|
|
|
|
func (s *DefaultLikeStore) BulkExists(ids []int, sentBy int, targetType string) (eids []int, err error) {
|
2020-04-10 01:32:02 +00:00
|
|
|
if len(ids) == 0 {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
var rows *sql.Rows
|
|
|
|
if len(ids) == 1 {
|
|
|
|
rows, err = s.singleExists.Query(sentBy, targetType, ids[0])
|
|
|
|
} else {
|
|
|
|
rows, err = qgen.NewAcc().Select("likes").Columns("targetItem").Where("sentBy=? AND targetType=?").In("targetItem", ids).Query(sentBy, targetType)
|
|
|
|
}
|
2019-06-05 06:00:40 +00:00
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
return nil, nil
|
|
|
|
} else if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
var id int
|
|
|
|
for rows.Next() {
|
2019-10-19 10:33:59 +00:00
|
|
|
if err := rows.Scan(&id); err != nil {
|
2019-06-05 06:00:40 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2019-10-19 10:33:59 +00:00
|
|
|
eids = append(eids, id)
|
2019-06-05 06:00:40 +00:00
|
|
|
}
|
2019-08-31 22:07:34 +00:00
|
|
|
return eids, rows.Err()
|
2019-06-05 06:00:40 +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 *DefaultLikeStore) Delete(targetID int, targetType string) error {
|
|
|
|
_, err := s.delete.Exec(targetID, targetType)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-06-05 06:00:40 +00:00
|
|
|
// TODO: Write a test for this
|
|
|
|
// Count returns the total number of likes globally
|
|
|
|
func (s *DefaultLikeStore) Count() (count int) {
|
|
|
|
err := s.count.QueryRow().Scan(&count)
|
|
|
|
if err != nil {
|
|
|
|
LogError(err)
|
|
|
|
}
|
|
|
|
return count
|
2019-10-19 10:33:59 +00:00
|
|
|
}
|