From 1c0a3dd5b685ffe86c14227bd454f0caa376777c Mon Sep 17 00:00:00 2001 From: Azareal Date: Sat, 27 Jul 2019 08:36:06 +1000 Subject: [PATCH] Accept shorter session param names as these are so common. Prealloc in DefaultPollStore.BulkGetMap Shorten more variable names. Remove a bit of inline CSS in topic_alt_quick_reply --- common/menu_item_store.go | 20 ++++++++++---------- common/poll_store.go | 8 ++++---- common/routes_common.go | 4 ++-- templates/topic.html | 14 +++++++------- templates/topic_alt.html | 14 +++++++------- templates/topic_alt_posts.html | 8 ++++---- templates/topic_alt_quick_reply.html | 6 +++--- templates/topic_posts.html | 8 ++++---- templates/topics.html | 4 ++-- tickloop.go | 5 ++--- 10 files changed, 45 insertions(+), 46 deletions(-) diff --git a/common/menu_item_store.go b/common/menu_item_store.go index a792d432..8302e45d 100644 --- a/common/menu_item_store.go +++ b/common/menu_item_store.go @@ -3,8 +3,8 @@ package common import "sync" type DefaultMenuItemStore struct { - items map[int]MenuItem - itemLock sync.RWMutex + items map[int]MenuItem + lock sync.RWMutex } func NewDefaultMenuItemStore() *DefaultMenuItemStore { @@ -13,16 +13,16 @@ func NewDefaultMenuItemStore() *DefaultMenuItemStore { } } -func (store *DefaultMenuItemStore) Add(item MenuItem) { - store.itemLock.Lock() - defer store.itemLock.Unlock() - store.items[item.ID] = item +func (s *DefaultMenuItemStore) Add(item MenuItem) { + s.lock.Lock() + defer s.lock.Unlock() + s.items[item.ID] = item } -func (store *DefaultMenuItemStore) Get(id int) (MenuItem, error) { - store.itemLock.RLock() - item, ok := store.items[id] - store.itemLock.RUnlock() +func (s *DefaultMenuItemStore) Get(id int) (MenuItem, error) { + s.lock.RLock() + item, ok := s.items[id] + s.lock.RUnlock() if ok { return item, nil } diff --git a/common/poll_store.go b/common/poll_store.go index 942ea1d8..ce0e535b 100644 --- a/common/poll_store.go +++ b/common/poll_store.go @@ -146,14 +146,14 @@ func (s *DefaultPollStore) BulkGetMap(ids []int) (list map[int]*Poll, err error) // TODO: Add a function for the qlist stuff var qlist string - var pollIDList []interface{} - for _, id := range ids { - pollIDList = append(pollIDList, strconv.Itoa(id)) + idList := make([]interface{},len(ids)) + for i, id := range ids { + idList[i] = strconv.Itoa(id) qlist += "?," } qlist = qlist[0 : len(qlist)-1] - rows, err := qgen.NewAcc().Select("polls").Columns("pollID, parentID, parentTable, type, options, votes").Where("pollID IN(" + qlist + ")").Query(pollIDList...) + rows, err := qgen.NewAcc().Select("polls").Columns("pollID, parentID, parentTable, type, options, votes").Where("pollID IN(" + qlist + ")").Query(idList...) if err != nil { return list, err } diff --git a/common/routes_common.go b/common/routes_common.go index 2026061b..611f0a78 100644 --- a/common/routes_common.go +++ b/common/routes_common.go @@ -470,7 +470,7 @@ func NoSessionMismatch(w http.ResponseWriter, r *http.Request, user User) RouteE if err != nil { return LocalError("Bad Form", w, r, user) } - if r.FormValue("session") != user.Session { + if r.FormValue("session") != user.Session && r.FormValue("s") != user.Session { return SecurityError(w, r, user) } return nil @@ -496,7 +496,7 @@ func HandleUploadRoute(w http.ResponseWriter, r *http.Request, user User, maxFil } func NoUploadSessionMismatch(w http.ResponseWriter, r *http.Request, user User) RouteError { - if r.FormValue("session") != user.Session { + if r.FormValue("session") != user.Session && r.FormValue("s") != user.Session { return SecurityError(w, r, user) } return nil diff --git a/templates/topic.html b/templates/topic.html index edf277c9..c2fad3e8 100644 --- a/templates/topic.html +++ b/templates/topic.html @@ -19,7 +19,7 @@ {{/** TODO: Does this need to be guarded by a permission? It's only visible in edit mode anyway, which can't be triggered, if they don't have the permission **/}} {{if not .Topic.IsClosed or .CurrentUser.Perms.CloseTopic}} {{if .CurrentUser.Perms.EditTopic}} -
+
{{end}} @@ -40,7 +40,7 @@    {{if .CurrentUser.Loggedin}} - {{if .CurrentUser.Perms.LikeItem}} + {{if .CurrentUser.Perms.LikeItem}} {{end}} @@ -49,15 +49,15 @@ {{if .CurrentUser.Perms.EditTopic}}{{end}} {{end}} - {{if .CurrentUser.Perms.DeleteTopic}}{{end}} + {{if .CurrentUser.Perms.DeleteTopic}}{{end}} - {{if .CurrentUser.Perms.CloseTopic}}{{if .Topic.IsClosed}}{{else}}{{end}}{{end}} + {{if .CurrentUser.Perms.CloseTopic}}{{if .Topic.IsClosed}}{{else}}{{end}}{{end}} - {{if .CurrentUser.Perms.PinTopic}}{{if .Topic.Sticky}}{{else}}{{end}}{{end}} + {{if .CurrentUser.Perms.PinTopic}}{{if .Topic.Sticky}}{{else}}{{end}}{{end}} {{if .CurrentUser.Perms.ViewIPs}}{{end}} {{end}} - + {{.Topic.LikeCount}} @@ -72,7 +72,7 @@ {{if .CurrentUser.Perms.CreateReply}} {{if not .Topic.IsClosed or .CurrentUser.Perms.CloseTopic}}
-
+
diff --git a/templates/topic_alt.html b/templates/topic_alt.html index 0439f16e..d11b3d42 100644 --- a/templates/topic_alt.html +++ b/templates/topic_alt.html @@ -16,7 +16,7 @@ {{if .CurrentUser.Loggedin}} {{if not .Topic.IsClosed or .CurrentUser.Perms.CloseTopic}} {{if .CurrentUser.Perms.EditTopic}} -
+
{{end}} @@ -29,7 +29,7 @@
- {{if .Poll.ID}}
+ {{if .Poll.ID}}
{{template "topic_alt_userinfo.html" .Topic }}
@@ -85,18 +85,18 @@
{{if .CurrentUser.Loggedin}} - {{if .CurrentUser.Perms.LikeItem}}{{end}} + {{if .CurrentUser.Perms.LikeItem}}{{end}} {{if not .Topic.IsClosed or .CurrentUser.Perms.CloseTopic}} {{if .CurrentUser.Perms.EditTopic}}{{end}} {{end}} - {{if .CurrentUser.Perms.DeleteTopic}}{{end}} + {{if .CurrentUser.Perms.DeleteTopic}}{{end}} {{if .CurrentUser.Perms.CloseTopic}} - {{if .Topic.IsClosed}}{{else}}{{end}}{{end}} + {{if .Topic.IsClosed}}{{else}}{{end}}{{end}} {{if .CurrentUser.Perms.PinTopic}} - {{if .Topic.Sticky}}{{else}}{{end}}{{end}} + {{if .Topic.Sticky}}{{else}}{{end}}{{end}} {{if .CurrentUser.Perms.ViewIPs}}{{end}} - + {{end}}
diff --git a/templates/topic_alt_posts.html b/templates/topic_alt_posts.html index 56da19a1..7ab619ef 100644 --- a/templates/topic_alt_posts.html +++ b/templates/topic_alt_posts.html @@ -31,14 +31,14 @@
{{if $.CurrentUser.Loggedin}} - {{if $.CurrentUser.Perms.LikeItem}}{{end}} + {{if $.CurrentUser.Perms.LikeItem}}{{end}} {{if not $.Topic.IsClosed or $.CurrentUser.Perms.CloseTopic}} - {{if $.CurrentUser.Perms.EditReply}}{{end}} + {{if $.CurrentUser.Perms.EditReply}}{{end}} {{end}} - {{if $.CurrentUser.Perms.DeleteReply}}{{end}} + {{if $.CurrentUser.Perms.DeleteReply}}{{end}} {{if $.CurrentUser.Perms.ViewIPs}}{{end}} - + {{end}}
diff --git a/templates/topic_alt_quick_reply.html b/templates/topic_alt_quick_reply.html index 754ef0b3..f2ca5fc1 100644 --- a/templates/topic_alt_quick_reply.html +++ b/templates/topic_alt_quick_reply.html @@ -1,13 +1,13 @@
-
 
+
 
{{if .CurrentUser.Tag}}
{{else}}
{{end}}
-
+
@@ -29,7 +29,7 @@ {{if .CurrentUser.Perms.UploadFiles}} - +
{{end}}
diff --git a/templates/topic_posts.html b/templates/topic_posts.html index 54408af5..263a124b 100644 --- a/templates/topic_posts.html +++ b/templates/topic_posts.html @@ -13,17 +13,17 @@    - {{if $.CurrentUser.Perms.LikeItem}}{{if .Liked}}{{else}}{{end}}{{end}} + {{if $.CurrentUser.Perms.LikeItem}}{{if .Liked}}{{else}}{{end}}{{end}} {{if not $.Topic.IsClosed or $.CurrentUser.Perms.CloseTopic}} - {{if $.CurrentUser.Perms.EditReply}}{{end}} + {{if $.CurrentUser.Perms.EditReply}}{{end}} {{end}} - {{if $.CurrentUser.Perms.DeleteReply}}{{end}} + {{if $.CurrentUser.Perms.DeleteReply}}{{end}} {{if $.CurrentUser.Perms.ViewIPs}}{{end}} - + diff --git a/templates/topics.html b/templates/topics.html index c5ad5355..3100dad4 100644 --- a/templates/topics.html +++ b/templates/topics.html @@ -38,7 +38,7 @@ {{/** TODO: Have a seperate forum list for moving topics? Maybe an AJAX forum search compatible with plugin_guilds? **/}} {{/** TODO: Add ARIA attributes for this **/}}