Shorten a couple of attachment parameters.
Rename a mislabelled variable. Prealloc in DefaultUserStore.BulkGetMap. Prealloc in DefaultTopicStore.BulkGetMap. Shorten the names of some temps. Shorten a mssql querystring.
This commit is contained in:
parent
91f12e26a4
commit
22cb2701b2
|
@ -610,14 +610,14 @@ func ParseMessage(msg string, sectionID int, sectionType string /*, user User*/)
|
|||
|
||||
// TODO: Reduce the amount of code duplication
|
||||
if media.Type == "attach" {
|
||||
addImage(media.URL + "?sectionID=" + strconv.Itoa(sectionID) + "&sectionType=" + sectionType)
|
||||
addImage(media.URL + "?sid=" + strconv.Itoa(sectionID) + "&stype=" + sectionType)
|
||||
continue
|
||||
} else if media.Type == "image" {
|
||||
addImage(media.URL)
|
||||
continue
|
||||
} else if media.Type == "aother" {
|
||||
sb.Write(attachOpen)
|
||||
sb.WriteString(media.URL + "?sectionID=" + strconv.Itoa(sectionID) + "&sectionType=" + sectionType)
|
||||
sb.WriteString(media.URL + "?sid=" + strconv.Itoa(sectionID) + "&stype=" + sectionType)
|
||||
sb.Write(attachClose)
|
||||
i += urlLen
|
||||
lastItem = i
|
||||
|
|
|
@ -137,9 +137,9 @@ func (s *DefaultTopicStore) BulkGetMap(ids []int) (list map[int]*Topic, err erro
|
|||
|
||||
// TODO: Add a function for the qlist stuff
|
||||
var qlist string
|
||||
var idList []interface{}
|
||||
for _, id := range ids {
|
||||
idList = append(idList, 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]
|
||||
|
|
|
@ -141,7 +141,7 @@ func (store *DefaultUserStore) GetOffset(offset int, perPage int) (users []*User
|
|||
|
||||
// TODO: Optimise the query to avoid preparing it on the spot? Maybe, use knowledge of the most common IN() parameter counts?
|
||||
// TODO: ID of 0 should always error?
|
||||
func (mus *DefaultUserStore) BulkGetMap(ids []int) (list map[int]*User, err error) {
|
||||
func (s *DefaultUserStore) BulkGetMap(ids []int) (list map[int]*User, err error) {
|
||||
var idCount = len(ids)
|
||||
list = make(map[int]*User)
|
||||
if idCount == 0 {
|
||||
|
@ -149,7 +149,7 @@ func (mus *DefaultUserStore) BulkGetMap(ids []int) (list map[int]*User, err erro
|
|||
}
|
||||
|
||||
var stillHere []int
|
||||
sliceList := mus.cache.BulkGet(ids)
|
||||
sliceList := s.cache.BulkGet(ids)
|
||||
if len(sliceList) > 0 {
|
||||
for i, sliceItem := range sliceList {
|
||||
if sliceItem != nil {
|
||||
|
@ -165,19 +165,19 @@ func (mus *DefaultUserStore) BulkGetMap(ids []int) (list map[int]*User, err erro
|
|||
if len(ids) == 0 {
|
||||
return list, nil
|
||||
} else if len(ids) == 1 {
|
||||
topic, err := mus.Get(ids[0])
|
||||
user, err := s.Get(ids[0])
|
||||
if err != nil {
|
||||
return list, err
|
||||
}
|
||||
list[topic.ID] = topic
|
||||
list[user.ID] = user
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// TODO: Add a function for the qlist stuff
|
||||
var qlist string
|
||||
var idList []interface{}
|
||||
for _, id := range ids {
|
||||
idList = append(idList, 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]
|
||||
|
@ -189,14 +189,14 @@ func (mus *DefaultUserStore) BulkGetMap(ids []int) (list map[int]*User, err erro
|
|||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
user := &User{Loggedin: true}
|
||||
err := rows.Scan(&user.ID, &user.Name, &user.Group, &user.Active, &user.IsSuperAdmin, &user.Session, &user.Email, &user.RawAvatar, &user.Message, &user.URLPrefix, &user.URLName, &user.Level, &user.Score, &user.Liked, &user.LastIP, &user.TempGroup)
|
||||
u := &User{Loggedin: true}
|
||||
err := rows.Scan(&u.ID, &u.Name, &u.Group, &u.Active, &u.IsSuperAdmin, &u.Session, &u.Email, &u.RawAvatar, &u.Message, &u.URLPrefix, &u.URLName, &u.Level, &u.Score, &u.Liked, &u.LastIP, &u.TempGroup)
|
||||
if err != nil {
|
||||
return list, err
|
||||
}
|
||||
user.Init()
|
||||
mus.cache.Set(user)
|
||||
list[user.ID] = user
|
||||
u.Init()
|
||||
s.cache.Set(u)
|
||||
list[u.ID] = u
|
||||
}
|
||||
err = rows.Err()
|
||||
if err != nil {
|
||||
|
|
|
@ -1093,8 +1093,7 @@ func (adapter *MssqlAdapter) SimpleCount(name string, table string, where string
|
|||
if table == "" {
|
||||
return "", errors.New("You need a name for this table")
|
||||
}
|
||||
|
||||
var querystr = "SELECT COUNT(*) AS [count] FROM [" + table + "]"
|
||||
var querystr = "SELECT COUNT(*) FROM [" + table + "]"
|
||||
|
||||
// TODO: Add support for BETWEEN x.x
|
||||
if len(where) != 0 {
|
||||
|
|
|
@ -35,11 +35,11 @@ func ShowAttachment(w http.ResponseWriter, r *http.Request, user c.User, filenam
|
|||
return c.LocalError("Bad extension", w, r, user)
|
||||
}
|
||||
|
||||
sectionID, err := strconv.Atoi(r.FormValue("sectionID"))
|
||||
sectionID, err := strconv.Atoi(r.FormValue("sid"))
|
||||
if err != nil {
|
||||
return c.LocalError("The sectionID is not an integer", w, r, user)
|
||||
}
|
||||
var sectionTable = r.FormValue("sectionType")
|
||||
sectionTable := r.FormValue("stype")
|
||||
|
||||
var originTable string
|
||||
var originID, uploadedBy int
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
<div class="show_on_edit attach_edit_bay" type="topic" id="{{.Topic.ID}}">
|
||||
{{range .Topic.Attachments}}
|
||||
<div class="attach_item attach_item_item{{if .Image}} attach_image_holder{{end}}">
|
||||
{{if .Image}}<img src="//{{$.Header.Site.URL}}/attachs/{{.Path}}?sectionID={{.SectionID}}&sectionType=forums" height=24 width=24 />{{end}}
|
||||
{{if .Image}}<img src="//{{$.Header.Site.URL}}/attachs/{{.Path}}?sid={{.SectionID}}&stype=forums" height=24 width=24 />{{end}}
|
||||
<span class="attach_item_path" aid="{{.ID}}" fullPath="//{{$.Header.Site.URL}}/attachs/{{.Path}}">{{.Path}}</span>
|
||||
<button class="attach_item_select">{{lang "topic.select_button_text"}}</button>
|
||||
<button class="attach_item_copy">{{lang "topic.copy_button_text"}}</button>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<div class="show_on_block_edit attach_edit_bay" type="reply" id="{{.ID}}">
|
||||
{{range .Attachments}}
|
||||
<div class="attach_item attach_item_item{{if .Image}} attach_image_holder{{end}}">
|
||||
{{if .Image}}<img src="//{{$.Header.Site.URL}}/attachs/{{.Path}}?sectionID={{.SectionID}}&sectionType=forums" height=24 width=24 />{{end}}
|
||||
{{if .Image}}<img src="//{{$.Header.Site.URL}}/attachs/{{.Path}}?sid={{.SectionID}}&stype=forums" height=24 width=24 />{{end}}
|
||||
<span class="attach_item_path" aid="{{.ID}}" fullPath="//{{$.Header.Site.URL}}/attachs/{{.Path}}">{{.Path}}</span>
|
||||
<button class="attach_item_select">{{lang "topic.select_button_text"}}</button>
|
||||
<button class="attach_item_copy">{{lang "topic.copy_button_text"}}</button>
|
||||
|
|
Loading…
Reference in New Issue