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 = `
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. ❤️
-| ').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 = ''; } |