Shorten things.

This commit is contained in:
Azareal 2019-12-07 16:27:01 +10:00
parent 0fa9a3fca1
commit 501c0dff0a
10 changed files with 45 additions and 46 deletions

View File

@ -6,7 +6,7 @@ import "github.com/Azareal/Gosora/query_gen"
var Activity ActivityStream
type ActivityStream interface {
Add(alert Alert) (int, error)
Add(a Alert) (int, error)
Get(id int) (Alert, error)
Count() (count int)
}

View File

@ -169,11 +169,9 @@ func (auth *DefaultAuth) ForceLogout(uid int) error {
}
// Flush the user out of the cache
ucache := Users.GetCache()
if ucache != nil {
ucache.Remove(uid)
if uc := Users.GetCache(); uc != nil {
uc.Remove(uid)
}
return nil
}

View File

@ -48,12 +48,13 @@ type MemoryGroupStore struct {
func NewMemoryGroupStore() (*MemoryGroupStore, error) {
acc := qgen.NewAcc()
ug := "users_groups"
return &MemoryGroupStore{
groups: make(map[int]*Group),
groupCount: 0,
getAll: acc.Select("users_groups").Columns("gid, name, permissions, plugin_perms, is_mod, is_admin, is_banned, tag").Prepare(),
get: acc.Select("users_groups").Columns("name, permissions, plugin_perms, is_mod, is_admin, is_banned, tag").Where("gid = ?").Prepare(),
count: acc.Count("users_groups").Prepare(),
getAll: acc.Select(ug).Columns("gid, name, permissions, plugin_perms, is_mod, is_admin, is_banned, tag").Prepare(),
get: acc.Select(ug).Columns("name, permissions, plugin_perms, is_mod, is_admin, is_banned, tag").Where("gid = ?").Prepare(),
count: acc.Count(ug).Prepare(),
userCount: acc.Count("users").Where("group = ?").Prepare(),
}, acc.FirstError()
}

View File

@ -7,7 +7,7 @@ import (
"log"
"strconv"
"github.com/Azareal/Gosora/query_gen"
qgen "github.com/Azareal/Gosora/query_gen"
)
var Polls PollStore
@ -65,8 +65,8 @@ type DefaultPollStore struct {
createPoll *sql.Stmt
createPollOption *sql.Stmt
addVote *sql.Stmt
incrementVoteCount *sql.Stmt
incrementVoteCountForOption *sql.Stmt
incVoteCount *sql.Stmt
incVoteCountForOption *sql.Stmt
delete *sql.Stmt
//count *sql.Stmt
}
@ -84,8 +84,8 @@ func NewDefaultPollStore(cache PollCache) (*DefaultPollStore, error) {
createPoll: acc.Insert("polls").Columns("parentID, parentTable, type, options").Fields("?,?,?,?").Prepare(),
createPollOption: acc.Insert("polls_options").Columns("pollID, option, votes").Fields("?,?,0").Prepare(),
addVote: acc.Insert("polls_votes").Columns("pollID, uid, option, castAt, ipaddress").Fields("?,?,?,UTC_TIMESTAMP(),?").Prepare(),
incrementVoteCount: acc.Update("polls").Set("votes = votes + 1").Where("pollID = ?").Prepare(),
incrementVoteCountForOption: acc.Update("polls_options").Set("votes = votes + 1").Where("option = ? AND pollID = ?").Prepare(),
incVoteCount: acc.Update("polls").Set("votes = votes + 1").Where("pollID = ?").Prepare(),
incVoteCountForOption: acc.Update("polls_options").Set("votes = votes + 1").Where("option = ? AND pollID = ?").Prepare(),
//count: acc.SimpleCount("polls", "", ""),
}, acc.FirstError()
}
@ -239,11 +239,11 @@ func (s *DefaultPollStore) CastVote(optionIndex int, pollID int, uid int, ipaddr
if err != nil {
return err
}
_, err = s.incrementVoteCount.Exec(pollID)
_, err = s.incVoteCount.Exec(pollID)
if err != nil {
return err
}
_, err = s.incrementVoteCountForOption.Exec(optionIndex, pollID)
_, err = s.incVoteCountForOption.Exec(optionIndex, pollID)
return err
}

View File

@ -232,8 +232,8 @@ func userCheck(w http.ResponseWriter, r *http.Request, user *User) (header *Head
return header, nil
}
func PrepResources(user *User, header *Header, theme *Theme) {
header.AddSheet(theme.Name + "/main.css")
func PrepResources(user *User, h *Header, theme *Theme) {
h.AddSheet(theme.Name + "/main.css")
if len(theme.Resources) > 0 {
rlist := theme.Resources
@ -245,12 +245,12 @@ func PrepResources(user *User, header *Header, theme *Theme) {
extarr := strings.Split(resource.Name, ".")
ext := extarr[len(extarr)-1]
if ext == "css" {
header.AddSheet(resource.Name)
h.AddSheet(resource.Name)
} else if ext == "js" {
if resource.Async {
header.AddScriptAsync(resource.Name)
h.AddScriptAsync(resource.Name)
} else {
header.AddScript(resource.Name)
h.AddScript(resource.Name)
}
}
}
@ -269,7 +269,7 @@ func PrepResources(user *User, header *Header, theme *Theme) {
}
}
//fmt.Printf("tname %+v\n", tname)
header.AddPreScriptAsync("template_" + name + tname + ".js")
h.AddPreScriptAsync("template_" + name + tname + ".js")
}
addPreScript("topics_topic")
addPreScript("paginator")

View File

@ -24,17 +24,17 @@ func ThumbTask(thumbChan chan bool) {
acc := qgen.NewAcc()
err := acc.Select("users_avatar_queue").Columns("uid").Limit("0,5").EachInt(func(uid int) error {
// TODO: Do a bulk user fetch instead?
user, err := Users.Get(uid)
u, err := Users.Get(uid)
if err != nil {
return errors.WithStack(err)
}
// Has the avatar been removed or already been processed by the thumbnailer?
if len(user.RawAvatar) < 2 || user.RawAvatar[1] == '.' {
if len(u.RawAvatar) < 2 || u.RawAvatar[1] == '.' {
_, _ = acc.Delete("users_avatar_queue").Where("uid = ?").Run(uid)
return nil
}
_, err = os.Stat("./uploads/avatar_" + strconv.Itoa(user.ID) + user.RawAvatar)
_, err = os.Stat("./uploads/avatar_" + strconv.Itoa(u.ID) + u.RawAvatar)
if os.IsNotExist(err) {
_, _ = acc.Delete("users_avatar_queue").Where("uid = ?").Run(uid)
return nil
@ -43,22 +43,23 @@ func ThumbTask(thumbChan chan bool) {
}
// This means it's an external image, they aren't currently implemented, but this is here for when they are
if user.RawAvatar[0] != '.' {
if u.RawAvatar[0] != '.' {
return nil
}
/*if user.RawAvatar == ".gif" {
return nil
}*/
if user.RawAvatar != ".png" && user.RawAvatar != ".jpg" && user.RawAvatar != ".jpe" && user.RawAvatar != ".jpeg" && user.RawAvatar != ".jif" && user.RawAvatar != ".jfi" && user.RawAvatar != ".jfif" && user.RawAvatar != ".gif" && user.RawAvatar != "tiff" && user.RawAvatar != "tif" {
if u.RawAvatar != ".png" && u.RawAvatar != ".jpg" && u.RawAvatar != ".jpe" && u.RawAvatar != ".jpeg" && u.RawAvatar != ".jif" && u.RawAvatar != ".jfi" && u.RawAvatar != ".jfif" && u.RawAvatar != ".gif" && u.RawAvatar != "tiff" && u.RawAvatar != "tif" {
return nil
}
err = Thumbnailer.Resize(user.RawAvatar[1:], "./uploads/avatar_"+strconv.Itoa(user.ID)+user.RawAvatar, "./uploads/avatar_"+strconv.Itoa(user.ID)+"_tmp"+user.RawAvatar, "./uploads/avatar_"+strconv.Itoa(user.ID)+"_w48"+user.RawAvatar, 48)
ap := "./uploads/avatar_"
err = Thumbnailer.Resize(u.RawAvatar[1:], ap+strconv.Itoa(u.ID)+u.RawAvatar, ap+strconv.Itoa(u.ID)+"_tmp"+u.RawAvatar, ap+strconv.Itoa(u.ID)+"_w48"+u.RawAvatar, 48)
if err != nil {
return errors.WithStack(err)
}
err = user.ChangeAvatar("." + user.RawAvatar)
err = u.ChangeAvatar("." + u.RawAvatar)
if err != nil {
return errors.WithStack(err)
}

View File

@ -28,7 +28,7 @@ type WordFilterStore interface {
Get(id int) (*WordFilter, error)
Create(find string, replace string) (int, error)
Delete(id int) error
Update(id int, find string, replacement string) error
Update(id int, find string, replace string) error
Length() int
EstCount() int
Count() (count int)

View File

@ -13,7 +13,6 @@ func ForumList(w http.ResponseWriter, r *http.Request, user c.User, header *c.He
if skip || rerr != nil {
return rerr
}
header.Title = phrases.GetTitlePhrase("forums")
header.Zone = "forums"
header.Path = "/forums/"

View File

@ -14,7 +14,7 @@ func ReportSubmit(w http.ResponseWriter, r *http.Request, user c.User, sitemID s
if ferr != nil {
return ferr
}
js := (r.PostFormValue("js") == "1")
js := r.PostFormValue("js") == "1"
itemID, err := strconv.Atoi(sitemID)
if err != nil {