gosora/common/subscription.go
Azareal 6935637867 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 17:22:08 +10:00

49 lines
1.5 KiB
Go

package common
import (
"database/sql"
qgen "github.com/Azareal/Gosora/query_gen"
)
var Subscriptions SubscriptionStore
// ? Should we have a subscription store for each zone? topic, forum, etc?
type SubscriptionStore interface {
Add(uid, elementID int, elementType string) error
Delete(uid, targetID int, targetType string) error
DeleteResource(targetID int, targetType string) error
}
type DefaultSubscriptionStore struct {
add *sql.Stmt
delete *sql.Stmt
deleteResource *sql.Stmt
}
func NewDefaultSubscriptionStore() (*DefaultSubscriptionStore, error) {
acc := qgen.NewAcc()
ast := "activity_subscriptions"
return &DefaultSubscriptionStore{
add: acc.Insert(ast).Columns("user, targetID, targetType, level").Fields("?,?,?,2").Prepare(),
delete: acc.Delete(ast).Where("user=? AND targetID=? AND targetType=?").Prepare(),
deleteResource: acc.Delete(ast).Where("targetID=? AND targetType=?").Prepare(),
}, acc.FirstError()
}
func (s *DefaultSubscriptionStore) Add(uid, elementID int, elementType string) error {
_, err := s.add.Exec(uid, elementID, elementType)
return err
}
// TODO: Add a primary key to the activity subscriptions table
func (s *DefaultSubscriptionStore) Delete(uid, targetID int, targetType string) error {
_, err := s.delete.Exec(uid, targetID, targetType)
return err
}
func (s *DefaultSubscriptionStore) DeleteResource(targetID int, targetType string) error {
_, err := s.deleteResource.Exec(targetID, targetType)
return err
}