avoid loading as many alerts outside of the bounding box

This commit is contained in:
Azareal 2020-03-31 22:33:40 +10:00
parent fc6544d620
commit bc16b724c2
10 changed files with 35 additions and 17 deletions

View File

@ -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
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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

View File

@ -124,8 +124,8 @@ function updateAlertList(menuAlerts) {
}
function setAlertError(menuAlerts,msg) {
let alertListNode = menuAlerts.getElementsByClassName("alertList")[0];
alertListNode.innerHTML = "<div class='alertItem'>"+msg+"</div>";
let n = menuAlerts.getElementsByClassName("alertList")[0];
n.innerHTML = "<div class='alertItem'>"+msg+"</div>";
}
var alertsInitted = false;

View File

@ -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)
}