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
|
// TODO: Reduce the amount of code duplication
|
||||||
if media.Type == "attach" {
|
if media.Type == "attach" {
|
||||||
addImage(media.URL + "?sectionID=" + strconv.Itoa(sectionID) + "&sectionType=" + sectionType)
|
addImage(media.URL + "?sid=" + strconv.Itoa(sectionID) + "&stype=" + sectionType)
|
||||||
continue
|
continue
|
||||||
} else if media.Type == "image" {
|
} else if media.Type == "image" {
|
||||||
addImage(media.URL)
|
addImage(media.URL)
|
||||||
continue
|
continue
|
||||||
} else if media.Type == "aother" {
|
} else if media.Type == "aother" {
|
||||||
sb.Write(attachOpen)
|
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)
|
sb.Write(attachClose)
|
||||||
i += urlLen
|
i += urlLen
|
||||||
lastItem = i
|
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
|
// TODO: Add a function for the qlist stuff
|
||||||
var qlist string
|
var qlist string
|
||||||
var idList []interface{}
|
idList := make([]interface{},len(ids))
|
||||||
for _, id := range ids {
|
for i, id := range ids {
|
||||||
idList = append(idList, strconv.Itoa(id))
|
idList[i] = strconv.Itoa(id)
|
||||||
qlist += "?,"
|
qlist += "?,"
|
||||||
}
|
}
|
||||||
qlist = qlist[0 : len(qlist)-1]
|
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: 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?
|
// 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)
|
var idCount = len(ids)
|
||||||
list = make(map[int]*User)
|
list = make(map[int]*User)
|
||||||
if idCount == 0 {
|
if idCount == 0 {
|
||||||
|
@ -149,7 +149,7 @@ func (mus *DefaultUserStore) BulkGetMap(ids []int) (list map[int]*User, err erro
|
||||||
}
|
}
|
||||||
|
|
||||||
var stillHere []int
|
var stillHere []int
|
||||||
sliceList := mus.cache.BulkGet(ids)
|
sliceList := s.cache.BulkGet(ids)
|
||||||
if len(sliceList) > 0 {
|
if len(sliceList) > 0 {
|
||||||
for i, sliceItem := range sliceList {
|
for i, sliceItem := range sliceList {
|
||||||
if sliceItem != nil {
|
if sliceItem != nil {
|
||||||
|
@ -165,19 +165,19 @@ func (mus *DefaultUserStore) BulkGetMap(ids []int) (list map[int]*User, err erro
|
||||||
if len(ids) == 0 {
|
if len(ids) == 0 {
|
||||||
return list, nil
|
return list, nil
|
||||||
} else if len(ids) == 1 {
|
} else if len(ids) == 1 {
|
||||||
topic, err := mus.Get(ids[0])
|
user, err := s.Get(ids[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return list, err
|
return list, err
|
||||||
}
|
}
|
||||||
list[topic.ID] = topic
|
list[user.ID] = user
|
||||||
return list, nil
|
return list, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add a function for the qlist stuff
|
// TODO: Add a function for the qlist stuff
|
||||||
var qlist string
|
var qlist string
|
||||||
var idList []interface{}
|
idList := make([]interface{},len(ids))
|
||||||
for _, id := range ids {
|
for i, id := range ids {
|
||||||
idList = append(idList, strconv.Itoa(id))
|
idList[i] = strconv.Itoa(id)
|
||||||
qlist += "?,"
|
qlist += "?,"
|
||||||
}
|
}
|
||||||
qlist = qlist[0 : len(qlist)-1]
|
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()
|
defer rows.Close()
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
user := &User{Loggedin: true}
|
u := &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)
|
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 {
|
if err != nil {
|
||||||
return list, err
|
return list, err
|
||||||
}
|
}
|
||||||
user.Init()
|
u.Init()
|
||||||
mus.cache.Set(user)
|
s.cache.Set(u)
|
||||||
list[user.ID] = user
|
list[u.ID] = u
|
||||||
}
|
}
|
||||||
err = rows.Err()
|
err = rows.Err()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1093,8 +1093,7 @@ func (adapter *MssqlAdapter) SimpleCount(name string, table string, where string
|
||||||
if table == "" {
|
if table == "" {
|
||||||
return "", errors.New("You need a name for this table")
|
return "", errors.New("You need a name for this table")
|
||||||
}
|
}
|
||||||
|
var querystr = "SELECT COUNT(*) FROM [" + table + "]"
|
||||||
var querystr = "SELECT COUNT(*) AS [count] FROM [" + table + "]"
|
|
||||||
|
|
||||||
// TODO: Add support for BETWEEN x.x
|
// TODO: Add support for BETWEEN x.x
|
||||||
if len(where) != 0 {
|
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)
|
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 {
|
if err != nil {
|
||||||
return c.LocalError("The sectionID is not an integer", w, r, user)
|
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 originTable string
|
||||||
var originID, uploadedBy int
|
var originID, uploadedBy int
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
<div class="show_on_edit attach_edit_bay" type="topic" id="{{.Topic.ID}}">
|
<div class="show_on_edit attach_edit_bay" type="topic" id="{{.Topic.ID}}">
|
||||||
{{range .Topic.Attachments}}
|
{{range .Topic.Attachments}}
|
||||||
<div class="attach_item attach_item_item{{if .Image}} attach_image_holder{{end}}">
|
<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>
|
<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_select">{{lang "topic.select_button_text"}}</button>
|
||||||
<button class="attach_item_copy">{{lang "topic.copy_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}}">
|
<div class="show_on_block_edit attach_edit_bay" type="reply" id="{{.ID}}">
|
||||||
{{range .Attachments}}
|
{{range .Attachments}}
|
||||||
<div class="attach_item attach_item_item{{if .Image}} attach_image_holder{{end}}">
|
<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>
|
<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_select">{{lang "topic.select_button_text"}}</button>
|
||||||
<button class="attach_item_copy">{{lang "topic.copy_button_text"}}</button>
|
<button class="attach_item_copy">{{lang "topic.copy_button_text"}}</button>
|
||||||
|
|
Loading…
Reference in New Issue