add a few more parser tests

save bytes in the parser
save allocs in external image embeds in the parser
save alloc bytes in convos
This commit is contained in:
Azareal 2020-03-28 14:48:42 +10:00
parent d3b2721746
commit 48b0b410c9
3 changed files with 37 additions and 28 deletions

View File

@ -251,10 +251,13 @@ func (s *DefaultConversationStore) GetUserExtra(uid, offset int) (cos []*Convers
var q string
idList := make([]interface{}, len(raw))
for i, co := range raw {
idList[i] = strconv.Itoa(co.ID)
q += "?,"
if i == 0 {
q = "?"
} else {
q += ",?"
}
idList[i] = strconv.Itoa(co.ID)
}
q = q[0 : len(q)-1]
rows, err := qgen.NewAcc().Select("conversations_participants").Columns("uid,cid").Where("cid IN(" + q + ")").Query(idList...)
if err != nil {

View File

@ -29,7 +29,7 @@ var URLOpenUser = []byte("<a rel='ugc'href='")
var URLOpen2 = []byte("'>")
var bytesSinglequote = []byte("'")
var bytesGreaterthan = []byte(">")
var urlMention = []byte(" class='mention'")
var urlMention = []byte("'class='mention'")
var URLClose = []byte("</a>")
var imageOpen = []byte("<a href=\"")
var imageOpen2 = []byte("\"><img src='")
@ -557,7 +557,6 @@ func ParseMessage(msg string, sectionID int, sectionType string, settings *Parse
sb.Write(URLOpen)
sb.WriteString(menUser.Link)
sb.Write(bytesSinglequote)
sb.Write(urlMention)
sb.Write(bytesGreaterthan)
sb.WriteByte('@')
@ -944,8 +943,8 @@ func parseMediaString(data string, settings *ParseSettings) (media MediaEmbed, o
if lastFrag := pathFrags[len(pathFrags)-1]; lastFrag != "" {
// TODO: Write a function for getting the file extension of a string
if extarr := strings.Split(lastFrag, "."); len(extarr) >= 2 {
ext := extarr[len(extarr)-1]
ext := strings.TrimPrefix(filepath.Ext(lastFrag),".")
if len(ext) != 0 {
if ImageFileExts.Contains(ext) {
media.Type = "image"
var sport string

View File

@ -231,6 +231,7 @@ func TestParser(t *testing.T) {
l.Add("//"+u+"\n//"+u, "<a href='"+fs+"'>"+c.Site.URL+"</a><br><a href='"+fs+"'>"+c.Site.URL+"</a>")
l.Add("http://"+u, "<a href='"+fs+"'>"+c.Site.URL+"</a>")
l.Add("https://"+u, "<a href='"+fs+"'>"+c.Site.URL+"</a>")
l.Add("//"+u+"/attachs/sha256hash.png?sid=1&stype=forums", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&amp;stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&amp;stype=forums'class='postImage'></a>")
l.Add("//"+u+"/attachs/sha256hash?sid=1&stype=forums", "<red>[Invalid URL]</red>")
l.Add("//"+u+"/attachs/s?sid=1&stype=forums", "<red>[Invalid URL]</red>")
@ -240,6 +241,12 @@ func TestParser(t *testing.T) {
l.Add("//"+u+"/attachs/sha256hash.png", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&amp;stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&amp;stype=forums'class='postImage'></a>")
l.Add("//"+u+"/attachs/sha256hash.png?sid=1", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&amp;stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&amp;stype=forums'class='postImage'></a>")
l.Add("//"+u+"/attachs/sha256hash.png?stype=forums", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&amp;stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&amp;stype=forums'class='postImage'></a>")
l.Add("//"+u+"/attachs/sha256hash.txt?sid=1&stype=forums", "<a download class='attach'href=\""+fs+"/attachs/sha256hash.txt?sid=1&amp;stype=forums\">Attachment</a>")
l.Add("//example.com/image.png", "<a href=\"//example.com/image.png\"><img src='//example.com/image.png'class='postImage'></a>")
l.Add("https://example.com/image.png", "<a href=\"https://example.com/image.png\"><img src='https://example.com/image.png'class='postImage'></a>")
l.Add("http://example.com/image.png", "<a href=\"http://example.com/image.png\"><img src='http://example.com/image.png'class='postImage'></a>")
}
local("localhost")
local("127.0.0.1")