diff --git a/server/activity_handler.go b/server/activity_handler.go index fc45567..6573a85 100644 --- a/server/activity_handler.go +++ b/server/activity_handler.go @@ -17,10 +17,8 @@ type jsonResponse struct { func ActivityHandler(db Database) echo.HandlerFunc { return func(c echo.Context) error { locale := LocaleForRequest(c.Request()) - filter := func(a Activity) bool { - return true - } - if c.QueryParam("nohelp") == "true" { + var filter func(Activity) bool + if c.QueryParams().Has("nohelp") && c.QueryParam("nohelp") != "false" { filter = func(a Activity) bool { if fp, ok := a.(*ForumPost); ok { if fp.ForumId == locale.HelpForumId { @@ -52,6 +50,7 @@ func ActivityHandler(db Database) echo.HandlerFunc { Data: a, }) } + c.Response().Header().Add("Cache-Control", "max-age=120") return c.JSON(200, response) } } diff --git a/server/bolt_database.go b/server/bolt_database.go index 5b23285..5ded537 100644 --- a/server/bolt_database.go +++ b/server/bolt_database.go @@ -66,7 +66,7 @@ func (db *BoltDatabase) Activity(locale *Locale, start string, count int, filter activity, err := unmarshalActivity(k, v) if err != nil { return err - } else if activity != nil && locale.ActivityFilter(activity) && filter(activity) { + } else if activity != nil && locale.ActivityFilter(activity) && (filter == nil || filter(activity)) { ret = append(ret, activity) next = base64.RawURLEncoding.EncodeToString(k) } diff --git a/server/dynamodb_database.go b/server/dynamodb_database.go index d498949..cf7bdbc 100644 --- a/server/dynamodb_database.go +++ b/server/dynamodb_database.go @@ -106,28 +106,42 @@ func (db *DynamoDBDatabase) Activity(locale *Locale, start string, count int, fi } for len(activity) < count { + batchSize := count - len(activity) + if filter != nil { + // if we're filtering results, fetch extra + batchSize = count * 4 + if batchSize < 50 { + batchSize = 50 + } else if batchSize > 1000 { + batchSize = 1000 + } + } result, err := db.client.QueryRequest(&dynamodb.QueryInput{ TableName: aws.String(db.tableName), KeyConditionExpression: aws.String(condition), ExpressionAttributeValues: attributeValues, ExclusiveStartKey: startKey, - Limit: aws.Int64(int64(count - len(activity))), + Limit: aws.Int64(int64(batchSize)), ScanIndexForward: aws.Bool(false), }).Send(context.Background()) if err != nil { return nil, "", err } + startKey = result.LastEvaluatedKey for _, item := range result.Items { if a, err := unmarshalActivity(item["rk"].B, item["v"].B); err != nil { return nil, "", err - } else if a != nil && filter(a) { + } else if a != nil && (filter == nil || filter(a)) { activity = append(activity, a) + if len(activity) == count { + startKey = item + break + } } } - if result.LastEvaluatedKey == nil { + if result.LastEvaluatedKey == nil || len(activity) == count { break } - startKey = result.LastEvaluatedKey } var next string diff --git a/server/index_handler.go b/server/index_handler.go index 927177e..2a291b1 100644 --- a/server/index_handler.go +++ b/server/index_handler.go @@ -11,7 +11,7 @@ var index = ` GGG Tracker - + @@ -37,13 +37,14 @@ var index = ` {{end}} -
-

Tala moana, warrior! This website is approaching its 12th birthday! If you've found it useful over the years, you can now show your appreciation in the form of a recurring or one-time donation on GitHub! In addition to showing your appreciation, this offsets server costs and helps support further feature developments (Twitter/X support? Search? GenAI?).

-

Thanks, and stay safe out there, Exile. ❤️

-

{{call $.Translate "Activity"}}

-
+ {{if ne $.Locale.HelpForumId 0}} +
+ + +
+ {{end}} @@ -73,7 +74,7 @@ var index = ` - + ` diff --git a/server/localization.go b/server/localization.go index 860211d..61f5a4d 100644 --- a/server/localization.go +++ b/server/localization.go @@ -102,11 +102,13 @@ var Locales = []*Locale{ Subdomain: "br", Image: "static/images/locales/br.png", Translations: map[string]string{ - "Activity": "Atividade", - "Thread": "Discussão", - "Poster": "Autor", - "Time": "Hora", - "Forum": "Fórum", + "Activity": "Atividade", + "Thread": "Discussão", + "Poster": "Autor", + "Time": "Hora", + "Forum": "Fórum", + "Hide Help Forum": "Ocultar Fórum de Ajuda", + "Show Help Forum": "Mostrar Fórum de Ajuda", }, HelpForumId: 774, }, @@ -114,27 +116,41 @@ var Locales = []*Locale{ Subdomain: "ru", Image: "static/images/locales/ru.png", Translations: map[string]string{ - "Activity": "Активность", - "Thread": "Тема", - "Poster": "Автор", - "Time": "Время", - "Forum": "Форум", + "Activity": "Активность", + "Thread": "Тема", + "Poster": "Автор", + "Time": "Время", + "Forum": "Форум", + "Hide Help Forum": "Скрыть форум помощи", + "Show Help Forum": "Показать Форум Помощи", }, + HelpForumId: 1281, }, { - Subdomain: "th", - Image: "static/images/locales/th.png", + Subdomain: "th", + Image: "static/images/locales/th.png", + Translations: map[string]string{ + "Activity": "กิจกรรม", + "Thread": "กระทู้", + "Poster": "ผู้โพสต์", + "Time": "เวลา", + "Forum": "ฟอรั่ม", + "Hide Help Forum": "ซ่อนฟอรั่มช่วยเหลือ", + "Show Help Forum": "แสดงฟอรั่มช่วยเหลือ", + }, HelpForumId: 1011, }, { Subdomain: "de", Image: "static/images/locales/de.png", Translations: map[string]string{ - "Activity": "Aktivität", - "Thread": "Beitrag", - "Poster": "Verfasser", - "Time": "Datum", - "Forum": "Forum", + "Activity": "Aktivität", + "Thread": "Beitrag", + "Poster": "Verfasser", + "Time": "Datum", + "Forum": "Forum", + "Hide Help Forum": "Hilfeforum ausblenden", + "Show Help Forum": "Hilfeforum anzeigen", }, HelpForumId: 1123, }, @@ -142,11 +158,13 @@ var Locales = []*Locale{ Subdomain: "fr", Image: "static/images/locales/fr.png", Translations: map[string]string{ - "Activity": "Activité", - "Thread": "Fil de discussion", - "Poster": "Posteur", - "Time": "Date", - "Forum": "Forum", + "Activity": "Activité", + "Thread": "Fil de discussion", + "Poster": "Posteur", + "Time": "Date", + "Forum": "Forum", + "Hide Help Forum": "Masquer le forum d'aide", + "Show Help Forum": "Afficher le forum d'aide", }, HelpForumId: 1051, }, @@ -154,11 +172,13 @@ var Locales = []*Locale{ Subdomain: "es", Image: "static/images/locales/es.png", Translations: map[string]string{ - "Activity": "Actividad", - "Thread": "Tema", - "Poster": "Autor", - "Time": "Fecha", - "Forum": "Foro", + "Activity": "Actividad", + "Thread": "Tema", + "Poster": "Autor", + "Time": "Fecha", + "Forum": "Foro", + "Hide Help Forum": "Ocultar el foro de ayuda", + "Show Help Forum": "Mostrar el foro de ayuda", }, HelpForumId: 1193, }, diff --git a/server/static/index.js b/server/static/index.js index f402423..72d6e0e 100644 --- a/server/static/index.js +++ b/server/static/index.js @@ -1,4 +1,5 @@ var currentPage = undefined; +var currentHideHelp = undefined; var POE = { Forum: { @@ -18,18 +19,21 @@ var POE = { function loadActivity() { var params = new URLSearchParams(location.hash.replace(/^#/, '')); var page = params.get('page') || ''; - var nohelp = params.get('nohelp') || ''; - if (currentPage !== undefined && page == currentPage) { + var hideHelp = params.has('nohelp') && params.get('nohelp') !== 'false'; + if (currentPage !== undefined && page == currentPage && currentHideHelp !== undefined && hideHelp == currentHideHelp) { return; } var previousPage = currentPage; + var previousHideHelp = currentHideHelp; + currentPage = page; + currentHideHelp = hideHelp; - if (nohelp == 'true') { - $('#activity-table tbody').empty().append($('').append($('').append($('
').attr('colspan', 6).text('Loading...'))) - } + var canonicalNohelpParam = hideHelp ? '&nohelp' : ''; + + $('#activity-table tbody').empty().append($('
').attr('colspan', 6).text('Loading...'))) - $.get('activity.json?next=' + page + '&nohelp=' + nohelp, function(data) { + $.get('activity.json?next=' + page + canonicalNohelpParam, function(data) { var $tbody = $('#activity-table tbody'); $tbody.empty(); @@ -141,28 +145,23 @@ function loadActivity() { $tbody.append($tr); } - var nohelpText; - var nohelpHref; - if (nohelp != 'true') { - nohelpText = 'Hide Help Forum'; - nohelpHref = '#page=' + page + '&nohelp=true'; + if (hideHelp) { + $('#hide-help-forum').hide(); + $('#show-help-forum').attr('href', page ? '#page=' + page : '#').show(); } else { - nohelpText = 'Show Help Forum'; - nohelpHref = '#page=' + page + '&nohelp=false'; + $('#show-help-forum').hide(); + $('#hide-help-forum').attr('href', (page ? '#page=' + page + '&' : '#') + 'nohelp').show(); } - $('#help-toggle').empty().append($('').text(nohelpText).attr('href', nohelpHref).click(function() { - currentPage = undefined; - window.scrollTo(0, 0); - })); - $('#activity-nav').empty().append($('').text('Next Page').attr('href', '#page=' + data.next + '&nohelp=' + nohelp).click(function() { + $('#activity-nav').empty().append($('').text('Next Page').attr('href', '#page=' + data.next + canonicalNohelpParam).click(function() { window.scrollTo(0, 0); })); }).fail(function() { alert('Something went wrong. Better luck next time.'); currentPage = previousPage if (currentPage !== undefined) { - window.location.hash = 'page=' + currentPage; + var previousNohelpParam = previousHideHelp ? '&nohelp' : ''; + window.location.hash = 'page=' + currentPage + previousNohelpParam; } else { window.location.hash = ''; }