Mercurial > public > mercurial-scm > hg
comparison mercurial/peer.py @ 28436:8d38eab2777a
peer: add an iterbatcher interface
This is very much like ordinary batch(), but it will let me add a mode
for batch where we have pathologically large requests which are then
handled streamily. This will be a significant improvement for things
like remotefilelog, which may want to request thousands of entities at
once.
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 01 Mar 2016 18:39:25 -0500 |
parents | d549cbb5503d |
children | ead25aa27a43 |
comparison
equal
deleted
inserted
replaced
28435:176736afa886 | 28436:8d38eab2777a |
---|---|
39 return resref | 39 return resref |
40 return call | 40 return call |
41 def submit(self): | 41 def submit(self): |
42 raise NotImplementedError() | 42 raise NotImplementedError() |
43 | 43 |
44 class iterbatcher(batcher): | |
45 | |
46 def submit(self): | |
47 raise NotImplementedError() | |
48 | |
49 def results(self): | |
50 raise NotImplementedError() | |
51 | |
44 class localbatch(batcher): | 52 class localbatch(batcher): |
45 '''performs the queued calls directly''' | 53 '''performs the queued calls directly''' |
46 def __init__(self, local): | 54 def __init__(self, local): |
47 batcher.__init__(self) | 55 batcher.__init__(self) |
48 self.local = local | 56 self.local = local |
49 def submit(self): | 57 def submit(self): |
50 for name, args, opts, resref in self.calls: | 58 for name, args, opts, resref in self.calls: |
51 resref.set(getattr(self.local, name)(*args, **opts)) | 59 resref.set(getattr(self.local, name)(*args, **opts)) |
60 | |
61 class localiterbatcher(iterbatcher): | |
62 def __init__(self, local): | |
63 super(iterbatcher, self).__init__() | |
64 self.local = local | |
65 | |
66 def submit(self): | |
67 # submit for a local iter batcher is a noop | |
68 pass | |
69 | |
70 def results(self): | |
71 for name, args, opts, resref in self.calls: | |
72 yield getattr(self.local, name)(*args, **opts) | |
52 | 73 |
53 def batchable(f): | 74 def batchable(f): |
54 '''annotation for batchable methods | 75 '''annotation for batchable methods |
55 | 76 |
56 Such methods must implement a coroutine as follows: | 77 Such methods must implement a coroutine as follows: |
89 class peerrepository(object): | 110 class peerrepository(object): |
90 | 111 |
91 def batch(self): | 112 def batch(self): |
92 return localbatch(self) | 113 return localbatch(self) |
93 | 114 |
115 def iterbatch(self): | |
116 """Batch requests but allow iterating over the results. | |
117 | |
118 This is to allow interleaving responses with things like | |
119 progress updates for clients. | |
120 """ | |
121 return localiterbatcher(self) | |
122 | |
94 def capable(self, name): | 123 def capable(self, name): |
95 '''tell whether repo supports named capability. | 124 '''tell whether repo supports named capability. |
96 return False if not supported. | 125 return False if not supported. |
97 if boolean capability, return True. | 126 if boolean capability, return True. |
98 if string capability, return string.''' | 127 if string capability, return string.''' |