diff --git a/daemon.py b/daemon.py index c1798df37..84b1f78ac 100644 --- a/daemon.py +++ b/daemon.py @@ -5973,7 +5973,7 @@ def runDaemon(blogsInstance: bool,mediaInstance: bool, \ noreply=False,nolike=False,nopics=False, \ noannounce=False,cw=False,ocapAlways=False, \ useTor=False,maxReplies=64, \ - domainMaxPostsPerDay=8640,accountMaxPostsPerDay=8640, \ + domainMaxPostsPerDay=8640,accountMaxPostsPerDay=864, \ allowDeletion=False,debug=False,unitTest=False, \ instanceOnlySkillsSearch=False,sendThreads=[], \ useBlurHash=False) -> None: diff --git a/inbox.py b/inbox.py index e95f2a2cb..3d220afba 100644 --- a/inbox.py +++ b/inbox.py @@ -2042,6 +2042,11 @@ def runInboxQueue(recentPostsCache: {},maxRecentPosts: int, \ 'domains': {}, 'accounts': {} } + quotasLastUpdatePerMin=int(time.time()) + quotasPerMin={ + 'domains': {}, + 'accounts': {} + } heartBeatCtr=0 queueRestoreCtr=0 @@ -2105,13 +2110,21 @@ def runInboxQueue(recentPostsCache: {},maxRecentPosts: int, \ } quotasLastUpdateDaily=currTime + # clear the per minute quotas for maximum numbers of received posts + if currTime-quotasLastUpdatePerMin>60: + quotasPerMin={ + 'domains': {}, + 'accounts': {} + } + quotasLastUpdatePerMin=currTime + # limit the number of posts which can arrive per domain per day postDomain=queueJson['postDomain'] if postDomain: if domainMaxPostsPerDay>0: if quotasDaily['domains'].get(postDomain): if quotasDaily['domains'][postDomain]>domainMaxPostsPerDay: - print('DEBUG: Quota - Maximum posts for '+postDomain+' reached') + print('DEBUG: Quota per day - Maximum posts for '+postDomain+' reached') if len(queue)>0: queue.pop(0) continue @@ -2119,6 +2132,17 @@ def runInboxQueue(recentPostsCache: {},maxRecentPosts: int, \ else: quotasDaily['domains'][postDomain]=1 + if quotasPerMin['domains'].get(postDomain): + domainMaxPostsPerMin=int(domainMaxPostsPerDay/(24*60)) + if quotasPerMin['domains'][postDomain]>domainMaxPostsPerMin: + print('DEBUG: Quota per min - Maximum posts for '+postDomain+' reached') + if len(queue)>0: + queue.pop(0) + continue + quotasPerMin['domains'][postDomain]+=1 + else: + quotasPerMin['domains'][postDomain]=1 + if accountMaxPostsPerDay>0: postHandle=queueJson['postNickname']+'@'+postDomain if quotasDaily['accounts'].get(postHandle):