bring in changes from eehouse.org

This is what's been running for months, so committing it.
This commit is contained in:
Eric House 2019-07-06 11:13:50 -07:00
parent 475206a373
commit 1ce243904e

View file

@ -187,17 +187,17 @@ def notifyViaFCM( devids, typ, target ):
return success return success
def shouldSend(val): def shouldSend(val):
return g_sendAll or val == 1 pow = 1
# pow = 1 while pow < val: pow *= 2
# while pow < val: result = pow == val
# pow *= 3 # print "shouldSend(", val, ") =>", result
# return pow == val return result
# given a list of msgid, devid lists, figure out which messages should # given a list of msgid, devid lists, figure out which messages should
# be sent/resent now and mark them as sent. Backoff is based on # be sent/resent now and mark them as sent. Backoff is based on
# msgids: if the only messages a device has pending have been seen # msgids: if the only messages a device has pending have been seen
# before, backoff applies. # before, backoff applies.
def targetsAfterBackoff( msgs ): def targetsAfterBackoff( msgs, ignoreBackoff ):
global g_sent global g_sent
targets = {} targets = {}
for row in msgs: for row in msgs:
@ -206,8 +206,10 @@ def targetsAfterBackoff( msgs ):
if not msgid in g_sent: if not msgid in g_sent:
g_sent[msgid] = 0 g_sent[msgid] = 0
g_sent[msgid] += 1 g_sent[msgid] += 1
if shouldSend( g_sent[msgid] ): if ignoreBackoff or shouldSend( g_sent[msgid] ):
targets[devid] = row if not devid in targets: targets[devid] = []
targets[devid].append(row)
print "targetsAfterBackoff() using:", g_sent
return targets return targets
# devids is an array of (msgid, devid) tuples # devids is an array of (msgid, devid) tuples
@ -272,8 +274,8 @@ def main():
# print "got msgs:", len(devids) # print "got msgs:", len(devids)
if 0 < len(devids): if 0 < len(devids):
devids = addClntVers( g_con, devids ) devids = addClntVers( g_con, devids )
targets = targetsAfterBackoff( devids ) targets = targetsAfterBackoff( devids, False )
# print "got targets:", len(targets) print 'got', len(targets), 'targets'
if 0 < len(targets): if 0 < len(targets):
if 0 < emptyCount: print "" if 0 < emptyCount: print ""
emptyCount = 0 emptyCount = 0
@ -281,11 +283,11 @@ def main():
if g_debug: print "devices needing notification:", targets, '=>', if g_debug: print "devices needing notification:", targets, '=>',
toDelete = [] toDelete = []
for devid in targets.keys(): for devid in targets.keys():
target = targets[devid] for targetRow in targets[devid]:
if notifyViaFCM( asGCMIds(g_con, [devid], typ), typ, target ) \ if notifyViaFCM( asGCMIds(g_con, [devid], typ), typ, targetRow ) \
and 3 <= target['clntVers'] \ and 3 <= targetRow['clntVers'] \
and target['msg64']: and targetRow['msg64']:
toDelete.append( str(target['id']) ) toDelete.append( str(targetRow['id']) )
nSent += 1 nSent += 1
pruneSent( devids ) pruneSent( devids )
deleteMsgs( g_con, toDelete ) deleteMsgs( g_con, toDelete )