Calculate and send diffs on publish
This commit is contained in:
parent
888ad2aeff
commit
ab1aaea7f5
2 changed files with 7 additions and 6 deletions
|
@ -376,7 +376,7 @@ class Site(object):
|
||||||
|
|
||||||
# Update content.json on peers
|
# Update content.json on peers
|
||||||
@util.Noparallel()
|
@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)
|
published = [] # Successfully published (Peer)
|
||||||
publishers = [] # Publisher threads
|
publishers = [] # Publisher threads
|
||||||
|
|
||||||
|
@ -397,16 +397,16 @@ class Site(object):
|
||||||
random.shuffle(peers_more)
|
random.shuffle(peers_more)
|
||||||
peers += peers_more[0:limit*2]
|
peers += peers_more[0:limit*2]
|
||||||
|
|
||||||
self.log.info("Publishing %s to %s/%s peers (connected: %s)..." % (
|
self.log.info("Publishing %s to %s/%s peers (connected: %s) diffs: %s..." % (
|
||||||
inner_path, limit, len(self.peers), num_connected_peers
|
inner_path, limit, len(self.peers), num_connected_peers, diffs.keys()
|
||||||
))
|
))
|
||||||
|
|
||||||
if not peers:
|
if not peers:
|
||||||
return 0 # No peers found
|
return 0 # No peers found
|
||||||
|
|
||||||
event_done = gevent.event.AsyncResult()
|
event_done = gevent.event.AsyncResult()
|
||||||
for i in range(min(len(self.peers), limit, threads)):
|
for i in range(min(len(peers), limit, threads)):
|
||||||
publisher = gevent.spawn(self.publisher, inner_path, peers, published, limit, event_done)
|
publisher = gevent.spawn(self.publisher, inner_path, peers, published, limit, event_done, diffs)
|
||||||
publishers.append(publisher)
|
publishers.append(publisher)
|
||||||
|
|
||||||
event_done.get() # Wait for done
|
event_done.get() # Wait for done
|
||||||
|
|
|
@ -318,9 +318,10 @@ class UiWebsocket(object):
|
||||||
self.site.saveSettings()
|
self.site.saveSettings()
|
||||||
self.site.announce()
|
self.site.announce()
|
||||||
|
|
||||||
|
diffs = self.site.content_manager.getDiffs(inner_path)
|
||||||
event_name = "publish %s %s" % (self.site.address, inner_path)
|
event_name = "publish %s %s" % (self.site.address, inner_path)
|
||||||
called_instantly = RateLimit.isAllowed(event_name, 30)
|
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
|
notification = "linked" not in dir(thread) # Only display notification on first callback
|
||||||
thread.linked = True
|
thread.linked = True
|
||||||
if called_instantly: # Allowed to call instantly
|
if called_instantly: # Allowed to call instantly
|
||||||
|
|
Loading…
Reference in a new issue