From 876b29b7be214d0cba50e71eb664d81cf73f5fb2 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 16 Oct 2020 11:26:06 +0100 Subject: [PATCH] Maximum newswire posts per source is configurable --- daemon.py | 9 ++++++++- epicyon.py | 7 ++++++- newsdaemon.py | 4 +++- newswire.py | 2 +- tests.py | 6 +++--- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/daemon.py b/daemon.py index 10e1171e5..5db5756d7 100644 --- a/daemon.py +++ b/daemon.py @@ -11951,7 +11951,8 @@ def loadTokens(baseDir: str, tokensDict: {}, tokensLookup: {}) -> None: tokensLookup[token] = nickname -def runDaemon(showPublishedDateOnly: bool, +def runDaemon(maxNewswirePostsPerSource: int, + showPublishedDateOnly: bool, votingTimeMins: int, positiveVoting: bool, newswireVotesThreshold: int, @@ -12072,6 +12073,12 @@ def runDaemon(showPublishedDateOnly: bool, # or if positive voting is anabled to add the item to the news timeline httpd.newswireVotesThreshold = newswireVotesThreshold + # For each newswire source (account or rss feed) + # this is the maximum number of posts to show for each. + # This avoids one or two sources from dominating the news, + # and also prevents big feeds from slowing down page load times + httpd.maxNewswirePostsPerSource = maxNewswirePostsPerSource + # Show only the date at the bottom of posts, and not the time httpd.showPublishedDateOnly = showPublishedDateOnly diff --git a/epicyon.py b/epicyon.py index 775d68682..e3010b9c8 100644 --- a/epicyon.py +++ b/epicyon.py @@ -112,6 +112,10 @@ parser.add_argument('--i2pDomain', dest='i2pDomain', type=str, parser.add_argument('-p', '--port', dest='port', type=int, default=None, help='Port number to run on') +parser.add_argument('--postsPerSource', + dest='maxNewswirePostsPerSource', type=int, + default=5, + help='Maximum newswire posts per feed or account') parser.add_argument('--postcache', dest='maxRecentPosts', type=int, default=512, help='The maximum number of recent posts to store in RAM') @@ -1938,7 +1942,8 @@ if setTheme(baseDir, themeName, domain): print('Theme set to ' + themeName) if __name__ == "__main__": - runDaemon(args.dateonly, + runDaemon(args.maxNewswirePostsPerSource, + args.dateonly, args.votingtime, args.positivevoting, args.minimumvotes, diff --git a/newsdaemon.py b/newsdaemon.py index 68b24fc45..30b71e61c 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -225,7 +225,9 @@ def runNewswireDaemon(baseDir: str, httpd, # try to update the feeds newNewswire = None try: - newNewswire = getDictFromNewswire(httpd.session, baseDir) + newNewswire = \ + getDictFromNewswire(httpd.session, baseDir, + httpd.maxNewswirePostsPerSource) except Exception as e: print('WARN: unable to update newswire ' + str(e)) time.sleep(120) diff --git a/newswire.py b/newswire.py index 35b4524ae..cf269d09b 100644 --- a/newswire.py +++ b/newswire.py @@ -396,7 +396,7 @@ def addBlogsToNewswire(baseDir: str, newswire: {}, os.remove(newswireModerationFilename) -def getDictFromNewswire(session, baseDir: str) -> {}: +def getDictFromNewswire(session, baseDir: str, maxPostsPerSource: int) -> {}: """Gets rss feeds as a dictionary from newswire file """ subscriptionsFilename = baseDir + '/accounts/newswire.txt' diff --git a/tests.py b/tests.py index 1f1bc86d6..645c18ba3 100644 --- a/tests.py +++ b/tests.py @@ -288,7 +288,7 @@ def createServerAlice(path: str, domain: str, port: int, onionDomain = None i2pDomain = None print('Server running: Alice') - runDaemon(False, 0, False, 1, False, False, False, + runDaemon(5, False, 0, False, 1, False, False, False, 5, True, True, 'en', __version__, "instanceId", False, path, domain, onionDomain, i2pDomain, None, port, port, @@ -351,7 +351,7 @@ def createServerBob(path: str, domain: str, port: int, onionDomain = None i2pDomain = None print('Server running: Bob') - runDaemon(False, 0, False, 1, False, False, False, + runDaemon(5, False, 0, False, 1, False, False, False, 5, True, True, 'en', __version__, "instanceId", False, path, domain, onionDomain, i2pDomain, None, port, port, @@ -388,7 +388,7 @@ def createServerEve(path: str, domain: str, port: int, federationList: [], onionDomain = None i2pDomain = None print('Server running: Eve') - runDaemon(False, 0, False, 1, False, False, False, + runDaemon(5, False, 0, False, 1, False, False, False, 5, True, True, 'en', __version__, "instanceId", False, path, domain, onionDomain, i2pDomain, None, port, port,