Skip to content

Commit

Permalink
The forum page now uses EasyJSON to speed it up slightly.
Browse files Browse the repository at this point in the history
Added SemrushBot to the analytics rather than treating it as an unknown.
The word compatible is now skipped in UA to hopefully avoid allocating a little bit more.
The tickloop is a little more resilient against hard stale connections now.
Removed a temporary benchmark which was used for comparing the built-in JSON library to EasyJSON.

Added the semrush phrase.
  • Loading branch information
Azareal committed Feb 10, 2019
1 parent 5099162 commit d5a5842
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
13 changes: 8 additions & 5 deletions gen_router.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions general_test.go
Expand Up @@ -350,10 +350,6 @@ func BenchmarkTopicsGuestJSRouteParallelWithRouter(b *testing.B) {
obRoute(b, "/topics/?js=1")
}

func BenchmarkTopicsGuestEJSRouteParallelWithRouter(b *testing.B) {
obRoute(b, "/topics/?ejs=1")
}

func BenchmarkForumsGuestRouteParallelWithRouter(b *testing.B) {
obRoute(b, "/forums/")
}
Expand Down
1 change: 1 addition & 0 deletions langs/english.json
Expand Up @@ -190,6 +190,7 @@
"discourse":"Discourse Forum Onebox",
"lynx":"Lynx",

"semrush":"SemrushBot",
"zgrab":"Zgrab Application Scanner",
"suspicious":"Suspicious",
"unknown":"Unknown",
Expand Down
11 changes: 7 additions & 4 deletions router_gen/main.go
Expand Up @@ -221,6 +221,7 @@ func main() {
"blank",
"malformed",
"suspicious",
"semrush",
"zgrab",
}

Expand Down Expand Up @@ -255,6 +256,7 @@ func main() {
"Twitterbot",
"Discourse",

"SemrushBot",
"zgrab",
}

Expand Down Expand Up @@ -284,7 +286,8 @@ func main() {
"Twitterbot": "twitter",
"Discourse": "discourse",

"zgrab": "zgrab",
"SemrushBot": "semrush",
"zgrab": "zgrab",
}

var fileData = `// Code generated by Gosora's Router Generator. DO NOT EDIT.
Expand Down Expand Up @@ -554,7 +557,7 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
for _, item := range StringToBytes(ua) {
if (item > 64 && item < 91) || (item > 96 && item < 123) {
buffer = append(buffer, item)
} else if item == ' ' || item == '(' || item == ')' || item == '-' || (item > 47 && item < 58) || item == '_' || item == ';' || item == '.' || item == '+' || (item == ':' && bytes.Equal(buffer,[]byte("http"))) || item == ',' || item == '/' {
} else if item == ' ' || item == '(' || item == ')' || item == '-' || (item > 47 && item < 58) || item == '_' || item == ';' || item == '.' || item == '+' || item == '~' || (item == ':' && bytes.Equal(buffer,[]byte("http"))) || item == ',' || item == '/' {
if len(buffer) != 0 {
if len(buffer) > 2 {
// Use an unsafe zero copy conversion here just to use the switch, it's not safe for this string to escape from here, as it will get mutated, so do a regular string conversion in append
Expand All @@ -569,8 +572,8 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
os = "iphone"
case "Android":
os = "android"
case "like":
// Skip this word
case "like","compatible":
// Skip these words
default:
items = append(items, string(buffer))
}
Expand Down
3 changes: 1 addition & 2 deletions routes/forum.go
Expand Up @@ -2,7 +2,6 @@ package routes

import (
"database/sql"
"encoding/json"
"net/http"
"strconv"

Expand Down Expand Up @@ -114,7 +113,7 @@ func ViewForum(w http.ResponseWriter, r *http.Request, user common.User, header

// TODO: Reduce the amount of boilerplate here
if r.FormValue("js") == "1" {
outBytes, err := json.Marshal(wsTopicList(topicList, lastPage))
outBytes, err := wsTopicList(topicList, lastPage).MarshalJSON()
if err != nil {
return common.InternalError(err, w, r)
}
Expand Down
3 changes: 3 additions & 0 deletions tickloop.go
Expand Up @@ -25,6 +25,7 @@ func startTick() (abort bool) {
if err != nil {
// TODO: There's a bit of a race here, but it doesn't matter if this error appears multiple times in the logs as it's capped at three times, we just want to cut it down 99% of the time
if isDBDown == 0 {
db.SetConnMaxLifetime(time.Second) // Drop all the connections and start over
common.LogWarning(err)
common.LogWarning(errors.New("The database is down"))
}
Expand All @@ -34,6 +35,8 @@ func startTick() (abort bool) {
if isDBDown == 1 {
log.Print("The database is back")
}
//db.SetConnMaxLifetime(time.Second * 60 * 5) // Make this infinite as the temporary lifetime change will purge the stale connections?
db.SetConnMaxLifetime(-1)
atomic.StoreInt32(&common.IsDBDown, 0)
return false
}
Expand Down

0 comments on commit d5a5842

Please sign in to comment.