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 // ! 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 // There can only be one hash link type starting with a specific character at the moment
hashType := hashLinkTypes[prefix[0]] hashType := hashLinkTypes[prefix[0]]
if hashType != "" { if hashType != "" {
return return
} }
hashLinkMap[prefix] = handler hashLinkMap[prefix] = h
hashLinkTypes[prefix[0]] = prefix hashLinkTypes[prefix[0]] = prefix
} }

View File

@ -43,7 +43,7 @@ func NewSQLReplyStore(acc *qgen.Accumulator, cache ReplyCache) (*SQLReplyStore,
return &SQLReplyStore{ return &SQLReplyStore{
cache: cache, cache: cache,
get: acc.Select(re).Columns("tid, content, createdBy, createdAt, lastEdit, lastEditBy, ip, likeCount, attachCount, actionType").Where("rid=?").Prepare(), 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(), 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(), 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(), count: acc.Count(re).Prepare(),

View File

@ -3,7 +3,7 @@
/* /*
* *
* Gosora MSSQL Interface * Gosora MSSQL Interface
* Copyright Azareal 2016 - 2019 * Copyright Azareal 2016 - 2020
* *
*/ */
package main package main
@ -78,6 +78,12 @@ func initMSSQL() (err error) {
return err 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.") 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] = ?") 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 { 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? // 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") 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 { if err != nil {
return errors.WithStack(err) 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.") 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` = ?") 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 { if err != nil {

View File

@ -1,6 +1,6 @@
// +build pgsql // +build pgsql
/* Copyright Azareal 2016 - 2019 */ /* Copyright Azareal 2016 - 2020 */
/* Super experimental and incomplete. DON'T USE IT YET! */ /* Super experimental and incomplete. DON'T USE IT YET! */
package main package main

View File

@ -124,13 +124,13 @@ function updateAlertList(menuAlerts) {
} }
function setAlertError(menuAlerts,msg) { function setAlertError(menuAlerts,msg) {
let alertListNode = menuAlerts.getElementsByClassName("alertList")[0]; let n = menuAlerts.getElementsByClassName("alertList")[0];
alertListNode.innerHTML = "<div class='alertItem'>"+msg+"</div>"; n.innerHTML = "<div class='alertItem'>"+msg+"</div>";
} }
var alertsInitted = false; var alertsInitted = false;
var lastTc = 0; var lastTc = 0;
function loadAlerts(menuAlerts, eTc=false) { function loadAlerts(menuAlerts,eTc=false) {
if(!alertsInitted) return; if(!alertsInitted) return;
let tc = ""; let tc = "";
if(eTc && lastTc != 0) tc = "&t=" + lastTc + "&c=" + alertCount; if(eTc && lastTc != 0) tc = "&t=" + lastTc + "&c=" + alertCount;
@ -787,7 +787,7 @@ function mainInit(){
$(".unix_to_24_hour_time").each(function(){ $(".unix_to_24_hour_time").each(function(){
let unixTime = this.innerText; let unixTime = this.innerText;
let date = new Date(unixTime*1000); let date = new Date(unixTime*1000);
console.log("date", date); console.log("date",date);
let minutes = "0" + date.getMinutes(); let minutes = "0" + date.getMinutes();
let formattedTime = date.getHours() + ":" + minutes.substr(-2); let formattedTime = date.getHours() + ":" + minutes.substr(-2);
console.log("formattedTime",formattedTime); console.log("formattedTime",formattedTime);
@ -814,8 +814,8 @@ function mainInit(){
}); });
this.onkeyup = function(ev) { this.onkeyup = function(ev) {
if(ev.which == 37) this.querySelectorAll("#prevFloat a")[0].click(); if(ev.which==37) this.querySelectorAll("#prevFloat a")[0].click();
if(ev.which == 39) this.querySelectorAll("#nextFloat a")[0].click(); if(ev.which==39) this.querySelectorAll("#nextFloat a")[0].click();
}; };
function asyncGetSheet(src) { function asyncGetSheet(src) {

View File

@ -119,7 +119,7 @@ func routeAPI(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError
var topCreatedAt int64 var topCreatedAt int64
if count != 0 { if count != 0 {
rows, err := stmts.getActivityFeedByWatcher.Query(user.ID) rows, err := stmts.getActivityFeedByWatcher.Query(user.ID, 12)
if err != nil { if err != nil {
return c.InternalErrorJS(err, w, r) return c.InternalErrorJS(err, w, r)
} }

View File

@ -7,11 +7,11 @@
<form action="/accounts/login/submit/" method="post"> <form action="/accounts/login/submit/" method="post">
<div class="formrow login_name_row"> <div class="formrow login_name_row">
<div class="formitem formlabel"><a id="login_name_label">{{lang "login_account_name"}}</a></div> <div class="formitem formlabel"><a id="login_name_label">{{lang "login_account_name"}}</a></div>
<div class="formitem"><input name="username" type="text" placeholder="{{lang "login_account_name"}}" aria-labelledby="login_name_label" required></div> <div class="formitem"><input name="username"type="text"placeholder="{{lang "login_account_name"}}" aria-labelledby="login_name_label" required></div>
</div> </div>
<div class="formrow login_password_row"> <div class="formrow login_password_row">
<div class="formitem formlabel"><a id="login_password_label">{{lang "login_account_password"}}</a></div> <div class="formitem formlabel"><a id="login_password_label">{{lang "login_account_password"}}</a></div>
<div class="formitem"><input name="password" type="password" autocomplete="current-password" placeholder="*****" aria-labelledby="login_password_label" required></div> <div class="formitem"><input name="password"type="password"autocomplete="current-password"placeholder="*****"aria-labelledby="login_password_label" required></div>
</div> </div>
<div class="formrow login_button_row form_button_row"> <div class="formrow login_button_row form_button_row">
<div class="formitem"><button name="login-button" class="formbutton">{{lang "login_submit_button"}}</button></div> <div class="formitem"><button name="login-button" class="formbutton">{{lang "login_submit_button"}}</button></div>

View File

@ -28,7 +28,7 @@
</div> </div>
{{else}}<div class="formrow"> {{else}}<div class="formrow">
<div class="formitem formlabel"><a>{{lang "panel_setting_value"}}</a></div> <div class="formitem formlabel"><a>{{lang "panel_setting_value"}}</a></div>
<div class="formitem"><input name="value" type="text" value="{{.Setting.Content}}"></div> <div class="formitem"><input name="value"type="text"value="{{.Setting.Content}}"></div>
</div>{{end}} </div>{{end}}
<div class="formrow form_button_row"> <div class="formrow form_button_row">
<div class="formitem"><button name="panel-button" class="formbutton">{{lang "panel_setting_update_button"}}</button></div> <div class="formitem"><button name="panel-button" class="formbutton">{{lang "panel_setting_update_button"}}</button></div>

View File

@ -5,7 +5,7 @@
{{if lt .UserCount 30}} {{if lt .UserCount 30}}
{{range .Users}}<div class="rowitem"style="background-image:url('{{.Avatar}}');"> {{range .Users}}<div class="rowitem"style="background-image:url('{{.Avatar}}');">
<img src="{{.Avatar}}"class="bgsub"alt="Avatar"aria-hidden="true"> <img src="{{.Avatar}}"class="bgsub"alt="Avatar"aria-hidden="true">
<a class="rowTitle" href="{{.Link}}">{{.Name}}</a> <a class="rowTitle"href="{{.Link}}">{{.Name}}</a>
</div> </div>
{{else}}<div class="rowitem rowmsg">{{lang "widget.online_none_online"}}</div>{{end}} {{else}}<div class="rowitem rowmsg">{{lang "widget.online_none_online"}}</div>{{end}}
{{else}}<div class="rowitem rowmsg">{{langf "widget.online_some_online" .UserCount}}</div>{{end}} {{else}}<div class="rowitem rowmsg">{{langf "widget.online_some_online" .UserCount}}</div>{{end}}