diff --git a/.gitignore b/.gitignore index af37f1cd..e0915c2c 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ out/* config/config.go Gosora Install +template_*.go \ No newline at end of file diff --git a/common/forum_perms_store.go b/common/forum_perms_store.go index 75814c0a..9c2b8989 100644 --- a/common/forum_perms_store.go +++ b/common/forum_perms_store.go @@ -12,6 +12,7 @@ var FPStore ForumPermsStore type ForumPermsStore interface { Init() error + GetAllMap() (bigMap map[int]map[int]*ForumPerms) Get(fid int, gid int) (fperms *ForumPerms, err error) GetCopy(fid int, gid int) (fperms ForumPerms, err error) ReloadAll() error @@ -134,12 +135,11 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error { var forumPerm *ForumPerms if !ok { - forumPerm = BlankForumPerms() - } else { - forumPerm, ok = forumPerms[group.ID] - if !ok { - forumPerm = BlankForumPerms() - } + continue + } + forumPerm, ok = forumPerms[group.ID] + if !ok { + continue } if forumPerm.Overrides { @@ -149,7 +149,6 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error { } else if group.Perms.ViewTopic { group.CanSee = append(group.CanSee, fid) } - DebugDetail("group.ID: ", group.ID) DebugDetailf("forumPerm: %+v\n", forumPerm) DebugDetail("group.CanSee: ", group.CanSee) @@ -159,6 +158,22 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error { return nil } +// ! Throughput on this might be bad due to the excessive locking +func (fps *MemoryForumPermsStore) GetAllMap() (bigMap map[int]map[int]*ForumPerms) { + bigMap = make(map[int]map[int]*ForumPerms) + fps.evenLock.RLock() + for fid, subMap := range fps.evenForums { + bigMap[fid] = subMap + } + fps.evenLock.RUnlock() + fps.oddLock.RLock() + for fid, subMap := range fps.oddForums { + bigMap[fid] = subMap + } + fps.oddLock.RUnlock() + return bigMap +} + // TODO: Add a hook here and have plugin_guilds use it // TODO: Check if the forum exists? // TODO: Fix the races diff --git a/common/routes_common.go b/common/routes_common.go index 178d5693..8975f29f 100644 --- a/common/routes_common.go +++ b/common/routes_common.go @@ -2,7 +2,6 @@ package common import ( "html" - "log" "net" "net/http" "strconv" @@ -37,10 +36,8 @@ func simpleForumUserCheck(w http.ResponseWriter, r *http.Request, user *User, fi } fperms, err := FPStore.Get(fid, user.Group) - if err != nil { - // TODO: Refactor this - log.Printf("Unable to get the forum perms for Group #%d for User #%d", user.Group, user.ID) - return nil, PreError("Something weird happened", w, r) + if err != nil && err != ErrNoRows { + return headerLite, InternalError(err, w, r) } cascadeForumPerms(fperms, user) return headerLite, nil @@ -64,10 +61,8 @@ func forumUserCheck(w http.ResponseWriter, r *http.Request, user *User, fid int) } fperms, err := FPStore.Get(fid, user.Group) - if err != nil { - // TODO: Refactor this - log.Printf("Unable to get the forum perms for Group #%d for User #%d", user.Group, user.ID) - return nil, PreError("Something weird happened", w, r) + if err != nil && err != ErrNoRows { + return header, InternalError(err, w, r) } cascadeForumPerms(fperms, user) return header, rerr diff --git a/panel_routes.go b/panel_routes.go index 54a3b2f8..1fcdcb04 100644 --- a/panel_routes.go +++ b/panel_routes.go @@ -332,7 +332,9 @@ func routePanelForumsEdit(w http.ResponseWriter, r *http.Request, user common.Us continue } forumPerms, err := common.FPStore.Get(fid, group.ID) - if err != nil { + if err == ErrNoRows { + forumPerms = common.BlankForumPerms() + } else if err != nil { return common.InternalError(err, w, r) } gplist = append(gplist, common.GroupForumPermPreset{group, common.ForumPermsToGroupForumPreset(forumPerms)}) @@ -479,7 +481,7 @@ func routePanelForumsEditPermsAdvance(w http.ResponseWriter, r *http.Request, us forumPerms, err := common.FPStore.Get(fid, gid) if err == ErrNoRows { - return common.LocalError("The requested group doesn't exist.", w, r, user) + forumPerms = common.BlankForumPerms() } else if err != nil { return common.InternalError(err, w, r) } @@ -544,7 +546,7 @@ func routePanelForumsEditPermsAdvanceSubmit(w http.ResponseWriter, r *http.Reque forumPerms, err := common.FPStore.GetCopy(fid, gid) if err == ErrNoRows { - return common.LocalError("The requested group doesn't exist.", w, r, user) + forumPerms = *common.BlankForumPerms() } else if err != nil { return common.InternalError(err, w, r) }