Calculate and send diffs on publish

This commit is contained in:
HelloZeroNet 2016-04-06 13:57:19 +02:00
parent 888ad2aeff
commit ab1aaea7f5
2 changed files with 7 additions and 6 deletions

View file

@ -376,7 +376,7 @@ class Site(object):
# Update content.json on peers
@util.Noparallel()
def publish(self, limit="default", inner_path="content.json"):
def publish(self, limit="default", inner_path="content.json", diffs={}):
published = [] # Successfully published (Peer)
publishers = [] # Publisher threads
@ -397,16 +397,16 @@ class Site(object):
random.shuffle(peers_more)
peers += peers_more[0:limit*2]
self.log.info("Publishing %s to %s/%s peers (connected: %s)..." % (
inner_path, limit, len(self.peers), num_connected_peers
self.log.info("Publishing %s to %s/%s peers (connected: %s) diffs: %s..." % (
inner_path, limit, len(self.peers), num_connected_peers, diffs.keys()
))
if not peers:
return 0 # No peers found
event_done = gevent.event.AsyncResult()
for i in range(min(len(self.peers), limit, threads)):
publisher = gevent.spawn(self.publisher, inner_path, peers, published, limit, event_done)
for i in range(min(len(peers), limit, threads)):
publisher = gevent.spawn(self.publisher, inner_path, peers, published, limit, event_done, diffs)
publishers.append(publisher)
event_done.get() # Wait for done

View file

@ -318,9 +318,10 @@ class UiWebsocket(object):
self.site.saveSettings()
self.site.announce()
diffs = self.site.content_manager.getDiffs(inner_path)
event_name = "publish %s %s" % (self.site.address, inner_path)
called_instantly = RateLimit.isAllowed(event_name, 30)
thread = RateLimit.callAsync(event_name, 30, self.site.publish, 5, inner_path) # Only publish once in 30 seconds to 5 peer
thread = RateLimit.callAsync(event_name, 30, self.site.publish, 5, inner_path, diffs=diffs) # Only publish once in 30 seconds to 5 peer
notification = "linked" not in dir(thread) # Only display notification on first callback
thread.linked = True
if called_instantly: # Allowed to call instantly