Shorten some names and eliminate a few allocs.
This commit is contained in:
parent
430df1e325
commit
06f0779525
@ -13,10 +13,10 @@ func NewDefaultMenuItemStore() *DefaultMenuItemStore {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DefaultMenuItemStore) Add(item MenuItem) {
|
||||
func (s *DefaultMenuItemStore) Add(i MenuItem) {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
s.items[item.ID] = item
|
||||
s.items[i.ID] = i
|
||||
}
|
||||
|
||||
func (s *DefaultMenuItemStore) Get(id int) (MenuItem, error) {
|
||||
|
@ -23,10 +23,11 @@ type SQLProfileReplyStore struct {
|
||||
}
|
||||
|
||||
func NewSQLProfileReplyStore(acc *qgen.Accumulator) (*SQLProfileReplyStore, error) {
|
||||
ur := "users_replies"
|
||||
return &SQLProfileReplyStore{
|
||||
get: acc.Select("users_replies").Columns("uid, content, createdBy, createdAt, lastEdit, lastEditBy, ipaddress").Where("rid = ?").Prepare(),
|
||||
create: acc.Insert("users_replies").Columns("uid, content, parsed_content, createdAt, createdBy, ipaddress").Fields("?,?,?,UTC_TIMESTAMP(),?,?").Prepare(),
|
||||
count: acc.Count("users_replies").Prepare(),
|
||||
get: acc.Select(ur).Columns("uid, content, createdBy, createdAt, lastEdit, lastEditBy, ipaddress").Where("rid = ?").Prepare(),
|
||||
create: acc.Insert(ur).Columns("uid, content, parsed_content, createdAt, createdBy, ipaddress").Fields("?,?,?,UTC_TIMESTAMP(),?,?").Prepare(),
|
||||
count: acc.Count(ur).Prepare(),
|
||||
}, acc.FirstError()
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ type ReplyStmts struct {
|
||||
func init() {
|
||||
DbInits.Add(func(acc *qgen.Accumulator) error {
|
||||
replyStmts = ReplyStmts{
|
||||
isLiked: acc.Select("likes").Columns("targetItem").Where("sentBy = ? and targetItem = ? and targetType = 'replies'").Prepare(),
|
||||
isLiked: acc.Select("likes").Columns("targetItem").Where("sentBy = ? and targetItem = ? and targetType='replies'").Prepare(),
|
||||
createLike: acc.Insert("likes").Columns("weight, targetItem, targetType, sentBy").Fields("?,?,?,?").Prepare(),
|
||||
edit: acc.Update("replies").Set("content = ?, parsed_content = ?").Where("rid = ? AND poll = 0").Prepare(),
|
||||
setPoll: acc.Update("replies").Set("poll = ?").Where("rid = ? AND poll = 0").Prepare(),
|
||||
|
@ -8,7 +8,7 @@ var Rstore ReplyStore
|
||||
|
||||
type ReplyStore interface {
|
||||
Get(id int) (*Reply, error)
|
||||
Create(topic *Topic, content string, ipaddress string, uid int) (id int, err error)
|
||||
Create(topic *Topic, content string, ip string, uid int) (id int, err error)
|
||||
Count() (count int)
|
||||
|
||||
SetCache(cache ReplyCache)
|
||||
@ -27,11 +27,12 @@ func NewSQLReplyStore(acc *qgen.Accumulator, cache ReplyCache) (*SQLReplyStore,
|
||||
if cache == nil {
|
||||
cache = NewNullReplyCache()
|
||||
}
|
||||
re := "replies"
|
||||
return &SQLReplyStore{
|
||||
cache: cache,
|
||||
get: acc.Select("replies").Columns("tid, content, createdBy, createdAt, lastEdit, lastEditBy, ipaddress, likeCount, attachCount, actionType").Where("rid = ?").Prepare(),
|
||||
create: acc.Insert("replies").Columns("tid, content, parsed_content, createdAt, lastUpdated, ipaddress, words, createdBy").Fields("?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?").Prepare(),
|
||||
count: acc.Count("replies").Prepare(),
|
||||
get: acc.Select(re).Columns("tid, content, createdBy, createdAt, lastEdit, lastEditBy, ipaddress, likeCount, attachCount, actionType").Where("rid = ?").Prepare(),
|
||||
create: acc.Insert(re).Columns("tid, content, parsed_content, createdAt, lastUpdated, ipaddress, words, createdBy").Fields("?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?").Prepare(),
|
||||
count: acc.Count(re).Prepare(),
|
||||
}, acc.FirstError()
|
||||
}
|
||||
|
||||
|
@ -62,11 +62,11 @@ func (tList *DefaultTopicList) Tick() error {
|
||||
|
||||
oddLists := make(map[int]*TopicListHolder)
|
||||
evenLists := make(map[int]*TopicListHolder)
|
||||
addList := func(gid int, holder *TopicListHolder) {
|
||||
addList := func(gid int, hold *TopicListHolder) {
|
||||
if gid%2 == 0 {
|
||||
evenLists[gid] = holder
|
||||
evenLists[gid] = hold
|
||||
} else {
|
||||
oddLists[gid] = holder
|
||||
oddLists[gid] = hold
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,19 +127,19 @@ func (tList *DefaultTopicList) GetListByGroup(group *Group, page int, orderby st
|
||||
}
|
||||
// TODO: Cache the first three pages not just the first along with all the topics on this beaten track
|
||||
if page == 1 && orderby == "" && len(filterIDs) == 0 {
|
||||
var holder *TopicListHolder
|
||||
var hold *TopicListHolder
|
||||
var ok bool
|
||||
if group.ID%2 == 0 {
|
||||
tList.evenLock.RLock()
|
||||
holder, ok = tList.evenGroups[group.ID]
|
||||
hold, ok = tList.evenGroups[group.ID]
|
||||
tList.evenLock.RUnlock()
|
||||
} else {
|
||||
tList.oddLock.RLock()
|
||||
holder, ok = tList.oddGroups[group.ID]
|
||||
hold, ok = tList.oddGroups[group.ID]
|
||||
tList.oddLock.RUnlock()
|
||||
}
|
||||
if ok {
|
||||
return holder.List, holder.ForumList, holder.Paginator, nil
|
||||
return hold.List, hold.ForumList, hold.Paginator, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,9 +153,9 @@ func (tList *DefaultTopicList) GetListByCanSee(canSee []int, page int, orderby s
|
||||
// We need a list of the visible forums for Quick Topic
|
||||
// ? - Would it be useful, if we could post in social groups from /topics/?
|
||||
for _, fid := range canSee {
|
||||
forum := Forums.DirtyGet(fid)
|
||||
if forum.Name != "" && forum.Active && (forum.ParentType == "" || forum.ParentType == "forum") {
|
||||
fcopy := forum.Copy()
|
||||
f := Forums.DirtyGet(fid)
|
||||
if f.Name != "" && f.Active && (f.ParentType == "" || f.ParentType == "forum") {
|
||||
fcopy := f.Copy()
|
||||
// TODO: Add a hook here for plugin_guilds
|
||||
forumList = append(forumList, fcopy)
|
||||
}
|
||||
@ -223,9 +223,9 @@ func (tList *DefaultTopicList) GetList(page int, orderby string, filterIDs []int
|
||||
// We need a list of the visible forums for Quick Topic
|
||||
// ? - Would it be useful, if we could post in social groups from /topics/?
|
||||
for _, fid := range canSee {
|
||||
forum := Forums.DirtyGet(fid)
|
||||
if forum.Name != "" && forum.Active && (forum.ParentType == "" || forum.ParentType == "forum") {
|
||||
fcopy := forum.Copy()
|
||||
f := Forums.DirtyGet(fid)
|
||||
if f.Name != "" && f.Active && (f.ParentType == "" || f.ParentType == "forum") {
|
||||
fcopy := f.Copy()
|
||||
// TODO: Add a hook here for plugin_guilds
|
||||
forumList = append(forumList, fcopy)
|
||||
}
|
||||
@ -260,7 +260,7 @@ func (tList *DefaultTopicList) getList(page int, orderby string, argList []inter
|
||||
}
|
||||
|
||||
// TODO: Prepare common qlist lengths to speed this up in common cases, prepared statements are prepared lazily anyway, so it probably doesn't matter if we do ten or so
|
||||
stmt, err := qgen.Builder.SimpleSelect("topics", "tid, title, content, createdBy, is_closed, sticky, createdAt, lastReplyAt, lastReplyBy, lastReplyID, parentID, views, postCount, likeCount, attachCount, poll, data", "parentID IN("+qlist+")", orderq, "?,?")
|
||||
stmt, err := qgen.Builder.SimpleSelect("topics", "tid,title,content,createdBy,is_closed,sticky,createdAt,lastReplyAt,lastReplyBy,lastReplyID,parentID,views,postCount,likeCount,attachCount,poll,data", "parentID IN("+qlist+")", orderq, "?,?")
|
||||
if err != nil {
|
||||
return nil, Paginator{nil, 1, 1}, err
|
||||
}
|
||||
@ -338,8 +338,7 @@ func (tList *DefaultTopicList) getList(page int, orderby string, argList []inter
|
||||
}
|
||||
}
|
||||
}
|
||||
err = rows.Err()
|
||||
if err != nil {
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, Paginator{nil, 1, 1}, err
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ func (s *DefaultTopicStore) Exists(id int) bool {
|
||||
return s.exists.QueryRow(id).Scan(&id) == nil
|
||||
}
|
||||
|
||||
func (s *DefaultTopicStore) Create(fid int, topicName string, content string, uid int, ipaddress string) (tid int, err error) {
|
||||
func (s *DefaultTopicStore) Create(fid int, topicName string, content string, uid int, ip string) (tid int, err error) {
|
||||
if topicName == "" {
|
||||
return 0, ErrNoTitle
|
||||
}
|
||||
@ -210,9 +210,9 @@ func (s *DefaultTopicStore) Create(fid int, topicName string, content string, ui
|
||||
if parsedContent == "" {
|
||||
return 0, ErrNoBody
|
||||
}
|
||||
|
||||
|
||||
// TODO: Move this statement into the topic store
|
||||
res, err := s.create.Exec(fid, topicName, content, parsedContent, uid, ipaddress, WordCount(content), uid)
|
||||
res, err := s.create.Exec(fid, topicName, content, parsedContent, uid, ip, WordCount(content), uid)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ type WordFilterStore interface {
|
||||
ReloadAll() error
|
||||
GetAll() (filters map[int]*WordFilter, err error)
|
||||
Get(id int) (*WordFilter, error)
|
||||
Create(find string, replacement string) (int, error)
|
||||
Create(find string, replace string) (int, error)
|
||||
Delete(id int) error
|
||||
Update(id int, find string, replacement string) error
|
||||
Length() int
|
||||
|
Loading…
Reference in New Issue
Block a user