Shorten some names and eliminate a few allocs.

This commit is contained in:
Azareal 2019-11-12 16:56:51 +10:00
parent 430df1e325
commit 06f0779525
7 changed files with 31 additions and 30 deletions

View File

@ -13,10 +13,10 @@ func NewDefaultMenuItemStore() *DefaultMenuItemStore {
} }
} }
func (s *DefaultMenuItemStore) Add(item MenuItem) { func (s *DefaultMenuItemStore) Add(i MenuItem) {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()
s.items[item.ID] = item s.items[i.ID] = i
} }
func (s *DefaultMenuItemStore) Get(id int) (MenuItem, error) { func (s *DefaultMenuItemStore) Get(id int) (MenuItem, error) {

View File

@ -23,10 +23,11 @@ type SQLProfileReplyStore struct {
} }
func NewSQLProfileReplyStore(acc *qgen.Accumulator) (*SQLProfileReplyStore, error) { func NewSQLProfileReplyStore(acc *qgen.Accumulator) (*SQLProfileReplyStore, error) {
ur := "users_replies"
return &SQLProfileReplyStore{ return &SQLProfileReplyStore{
get: acc.Select("users_replies").Columns("uid, content, createdBy, createdAt, lastEdit, lastEditBy, ipaddress").Where("rid = ?").Prepare(), get: acc.Select(ur).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(), create: acc.Insert(ur).Columns("uid, content, parsed_content, createdAt, createdBy, ipaddress").Fields("?,?,?,UTC_TIMESTAMP(),?,?").Prepare(),
count: acc.Count("users_replies").Prepare(), count: acc.Count(ur).Prepare(),
}, acc.FirstError() }, acc.FirstError()
} }

View File

@ -8,7 +8,7 @@ var Rstore ReplyStore
type ReplyStore interface { type ReplyStore interface {
Get(id int) (*Reply, error) 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) Count() (count int)
SetCache(cache ReplyCache) SetCache(cache ReplyCache)
@ -27,11 +27,12 @@ func NewSQLReplyStore(acc *qgen.Accumulator, cache ReplyCache) (*SQLReplyStore,
if cache == nil { if cache == nil {
cache = NewNullReplyCache() cache = NewNullReplyCache()
} }
re := "replies"
return &SQLReplyStore{ return &SQLReplyStore{
cache: cache, cache: cache,
get: acc.Select("replies").Columns("tid, content, createdBy, createdAt, lastEdit, lastEditBy, ipaddress, likeCount, attachCount, actionType").Where("rid = ?").Prepare(), get: acc.Select(re).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(), create: acc.Insert(re).Columns("tid, content, parsed_content, createdAt, lastUpdated, ipaddress, words, createdBy").Fields("?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?").Prepare(),
count: acc.Count("replies").Prepare(), count: acc.Count(re).Prepare(),
}, acc.FirstError() }, acc.FirstError()
} }

View File

@ -62,11 +62,11 @@ func (tList *DefaultTopicList) Tick() error {
oddLists := make(map[int]*TopicListHolder) oddLists := make(map[int]*TopicListHolder)
evenLists := 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 { if gid%2 == 0 {
evenLists[gid] = holder evenLists[gid] = hold
} else { } 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 // 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 { if page == 1 && orderby == "" && len(filterIDs) == 0 {
var holder *TopicListHolder var hold *TopicListHolder
var ok bool var ok bool
if group.ID%2 == 0 { if group.ID%2 == 0 {
tList.evenLock.RLock() tList.evenLock.RLock()
holder, ok = tList.evenGroups[group.ID] hold, ok = tList.evenGroups[group.ID]
tList.evenLock.RUnlock() tList.evenLock.RUnlock()
} else { } else {
tList.oddLock.RLock() tList.oddLock.RLock()
holder, ok = tList.oddGroups[group.ID] hold, ok = tList.oddGroups[group.ID]
tList.oddLock.RUnlock() tList.oddLock.RUnlock()
} }
if ok { 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 // We need a list of the visible forums for Quick Topic
// ? - Would it be useful, if we could post in social groups from /topics/? // ? - Would it be useful, if we could post in social groups from /topics/?
for _, fid := range canSee { for _, fid := range canSee {
forum := Forums.DirtyGet(fid) f := Forums.DirtyGet(fid)
if forum.Name != "" && forum.Active && (forum.ParentType == "" || forum.ParentType == "forum") { if f.Name != "" && f.Active && (f.ParentType == "" || f.ParentType == "forum") {
fcopy := forum.Copy() fcopy := f.Copy()
// TODO: Add a hook here for plugin_guilds // TODO: Add a hook here for plugin_guilds
forumList = append(forumList, fcopy) 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 // We need a list of the visible forums for Quick Topic
// ? - Would it be useful, if we could post in social groups from /topics/? // ? - Would it be useful, if we could post in social groups from /topics/?
for _, fid := range canSee { for _, fid := range canSee {
forum := Forums.DirtyGet(fid) f := Forums.DirtyGet(fid)
if forum.Name != "" && forum.Active && (forum.ParentType == "" || forum.ParentType == "forum") { if f.Name != "" && f.Active && (f.ParentType == "" || f.ParentType == "forum") {
fcopy := forum.Copy() fcopy := f.Copy()
// TODO: Add a hook here for plugin_guilds // TODO: Add a hook here for plugin_guilds
forumList = append(forumList, fcopy) forumList = append(forumList, fcopy)
} }
@ -338,8 +338,7 @@ func (tList *DefaultTopicList) getList(page int, orderby string, argList []inter
} }
} }
} }
err = rows.Err() if err = rows.Err(); err != nil {
if err != nil {
return nil, Paginator{nil, 1, 1}, err return nil, Paginator{nil, 1, 1}, err
} }

View File

@ -197,7 +197,7 @@ func (s *DefaultTopicStore) Exists(id int) bool {
return s.exists.QueryRow(id).Scan(&id) == nil 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 == "" { if topicName == "" {
return 0, ErrNoTitle return 0, ErrNoTitle
} }
@ -212,7 +212,7 @@ func (s *DefaultTopicStore) Create(fid int, topicName string, content string, ui
} }
// TODO: Move this statement into the topic store // 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 { if err != nil {
return 0, err return 0, err
} }

View File

@ -26,7 +26,7 @@ type WordFilterStore interface {
ReloadAll() error ReloadAll() error
GetAll() (filters map[int]*WordFilter, err error) GetAll() (filters map[int]*WordFilter, err error)
Get(id int) (*WordFilter, error) Get(id int) (*WordFilter, error)
Create(find string, replacement string) (int, error) Create(find string, replace string) (int, error)
Delete(id int) error Delete(id int) error
Update(id int, find string, replacement string) error Update(id int, find string, replacement string) error
Length() int Length() int