From bc16b724c24ab473044832195b51468f967776a7 Mon Sep 17 00:00:00 2001 From: Azareal Date: Tue, 31 Mar 2020 22:33:40 +1000 Subject: [PATCH] avoid loading as many alerts outside of the bounding box --- common/parser.go | 4 ++-- common/reply_store.go | 2 +- mssql.go | 8 +++++++- mysql.go | 14 +++++++++++++- pgsql.go | 2 +- public/global.js | 12 ++++++------ routes.go | 2 +- templates/login.html | 4 ++-- templates/panel_setting.html | 2 +- templates/widget_online.html | 2 +- 10 files changed, 35 insertions(+), 17 deletions(-) diff --git a/common/parser.go b/common/parser.go index 27d9177d..11b61d74 100644 --- a/common/parser.go +++ b/common/parser.go @@ -394,13 +394,13 @@ func peekMatch(cur int, phrase string, runes []rune) bool { } // ! Not concurrency safe -func AddHashLinkType(prefix string, handler func(*strings.Builder, string, *int)) { +func AddHashLinkType(prefix string, h func(*strings.Builder, string, *int)) { // There can only be one hash link type starting with a specific character at the moment hashType := hashLinkTypes[prefix[0]] if hashType != "" { return } - hashLinkMap[prefix] = handler + hashLinkMap[prefix] = h hashLinkTypes[prefix[0]] = prefix } diff --git a/common/reply_store.go b/common/reply_store.go index 96299a67..1879a6bf 100644 --- a/common/reply_store.go +++ b/common/reply_store.go @@ -43,7 +43,7 @@ func NewSQLReplyStore(acc *qgen.Accumulator, cache ReplyCache) (*SQLReplyStore, return &SQLReplyStore{ cache: cache, get: acc.Select(re).Columns("tid, content, createdBy, createdAt, lastEdit, lastEditBy, ip, likeCount, attachCount, actionType").Where("rid=?").Prepare(), - getAll: acc.Select(re).Columns("rid,tid, content, createdBy, createdAt, lastEdit, lastEditBy, ip, likeCount, attachCount, actionType").Prepare(), + getAll: acc.Select(re).Columns("rid,tid,content,createdBy,createdAt,lastEdit,lastEditBy,ip,likeCount,attachCount,actionType").Prepare(), exists: acc.Exists(re, "rid").Prepare(), create: acc.Insert(re).Columns("tid, content, parsed_content, createdAt, lastUpdated, ip, words, createdBy").Fields("?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?").Prepare(), count: acc.Count(re).Prepare(), diff --git a/mssql.go b/mssql.go index 2df58dde..6ba315f0 100644 --- a/mssql.go +++ b/mssql.go @@ -3,7 +3,7 @@ /* * * Gosora MSSQL Interface -* Copyright Azareal 2016 - 2019 +* Copyright Azareal 2016 - 2020 * */ package main @@ -78,6 +78,12 @@ func initMSSQL() (err error) { return err } + log.Print("Preparing getActivityFeedByWatcher statement.") + stmts.getActivityFeedByWatcherStmt, err = db.Prepare("SELECT activity_stream_matches.asid, activity_stream.actor, activity_stream.targetUser, activity_stream.event, activity_stream.elementType, activity_stream.elementID, activity_stream.createdAt FROM [activity_stream_matches] INNER JOIN [activity_stream] ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE [watcher] = ? ORDER BY activity_stream.asid DESC OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY") + if err != nil { + return err + } + log.Print("Preparing getActivityCountByWatcher statement.") stmts.getActivityCountByWatcherStmt, err = db.Prepare("SELECT count(*) FROM [activity_stream_matches] INNER JOIN [activity_stream] ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE [watcher] = ?") if err != nil { diff --git a/mysql.go b/mysql.go index e1a7277a..a352666d 100644 --- a/mysql.go +++ b/mysql.go @@ -53,12 +53,24 @@ func initMySQL() (err error) { } // TODO: Is there a less noisy way of doing this for tests? - log.Print("Preparing getActivityFeedByWatcher statement.") + /*log.Print("Preparing getActivityFeedByWatcher statement.") stmts.getActivityFeedByWatcher, err = db.Prepare("SELECT activity_stream_matches.asid, activity_stream.actor, activity_stream.targetUser, activity_stream.event, activity_stream.elementType, activity_stream.elementID, activity_stream.createdAt FROM `activity_stream_matches` INNER JOIN `activity_stream` ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE `watcher` = ? ORDER BY activity_stream.asid DESC LIMIT 16") + if err != nil { + return errors.WithStack(err) + }*/ + + log.Print("Preparing getActivityFeedByWatcher statement.") + stmts.getActivityFeedByWatcher, err = db.Prepare("SELECT activity_stream_matches.asid, activity_stream.actor, activity_stream.targetUser, activity_stream.event, activity_stream.elementType, activity_stream.elementID, activity_stream.createdAt FROM `activity_stream_matches` INNER JOIN `activity_stream` ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE `watcher` = ? ORDER BY activity_stream.asid DESC LIMIT ?") if err != nil { return errors.WithStack(err) } + /*log.Print("Preparing getActivityFeedByWatcherAfter statement.") + stmts.getActivityFeedByWatcherAfter, err = db.Prepare("SELECT activity_stream_matches.asid, activity_stream.actor, activity_stream.targetUser, activity_stream.event, activity_stream.elementType, activity_stream.elementID, activity_stream.createdAt FROM `activity_stream_matches` INNER JOIN `activity_stream` ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE `watcher` = ? AND createdAt => ? ORDER BY activity_stream.asid DESC LIMIT ?") + if err != nil { + return errors.WithStack(err) + }*/ + log.Print("Preparing getActivityCountByWatcher statement.") stmts.getActivityCountByWatcher, err = db.Prepare("SELECT count(*) FROM `activity_stream_matches` INNER JOIN `activity_stream` ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE `watcher` = ?") if err != nil { diff --git a/pgsql.go b/pgsql.go index ab9542c8..f365a772 100644 --- a/pgsql.go +++ b/pgsql.go @@ -1,6 +1,6 @@ // +build pgsql -/* Copyright Azareal 2016 - 2019 */ +/* Copyright Azareal 2016 - 2020 */ /* Super experimental and incomplete. DON'T USE IT YET! */ package main diff --git a/public/global.js b/public/global.js index e95973ec..e06e1104 100644 --- a/public/global.js +++ b/public/global.js @@ -124,13 +124,13 @@ function updateAlertList(menuAlerts) { } function setAlertError(menuAlerts,msg) { - let alertListNode = menuAlerts.getElementsByClassName("alertList")[0]; - alertListNode.innerHTML = "
"+msg+"
"; + let n = menuAlerts.getElementsByClassName("alertList")[0]; + n.innerHTML = "
"+msg+"
"; } var alertsInitted = false; var lastTc = 0; -function loadAlerts(menuAlerts, eTc=false) { +function loadAlerts(menuAlerts,eTc=false) { if(!alertsInitted) return; let tc = ""; if(eTc && lastTc != 0) tc = "&t=" + lastTc + "&c=" + alertCount; @@ -787,7 +787,7 @@ function mainInit(){ $(".unix_to_24_hour_time").each(function(){ let unixTime = this.innerText; let date = new Date(unixTime*1000); - console.log("date", date); + console.log("date",date); let minutes = "0" + date.getMinutes(); let formattedTime = date.getHours() + ":" + minutes.substr(-2); console.log("formattedTime",formattedTime); @@ -814,8 +814,8 @@ function mainInit(){ }); this.onkeyup = function(ev) { - if(ev.which == 37) this.querySelectorAll("#prevFloat a")[0].click(); - if(ev.which == 39) this.querySelectorAll("#nextFloat a")[0].click(); + if(ev.which==37) this.querySelectorAll("#prevFloat a")[0].click(); + if(ev.which==39) this.querySelectorAll("#nextFloat a")[0].click(); }; function asyncGetSheet(src) { diff --git a/routes.go b/routes.go index df915037..10df352d 100644 --- a/routes.go +++ b/routes.go @@ -119,7 +119,7 @@ func routeAPI(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError var topCreatedAt int64 if count != 0 { - rows, err := stmts.getActivityFeedByWatcher.Query(user.ID) + rows, err := stmts.getActivityFeedByWatcher.Query(user.ID, 12) if err != nil { return c.InternalErrorJS(err, w, r) } diff --git a/templates/login.html b/templates/login.html index cfd9a449..a24f7bc1 100644 --- a/templates/login.html +++ b/templates/login.html @@ -7,11 +7,11 @@
{{else}}{{end}}
diff --git a/templates/widget_online.html b/templates/widget_online.html index 68fda6ff..de0c5b95 100644 --- a/templates/widget_online.html +++ b/templates/widget_online.html @@ -5,7 +5,7 @@ {{if lt .UserCount 30}} {{range .Users}} {{else}}
{{lang "widget.online_none_online"}}
{{end}} {{else}}
{{langf "widget.online_some_online" .UserCount}}
{{end}}