ansible: make key_from_kwargs() 10x faster
It was half the cost of the service call
This commit is contained in:
parent
79c2d6c289
commit
95039eea11
|
@ -38,6 +38,7 @@ when a child has completed a job.
|
|||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
import hashlib
|
||||
import logging
|
||||
import os
|
||||
import os.path
|
||||
|
@ -114,11 +115,19 @@ class ContextService(mitogen.service.Service):
|
|||
|
||||
def key_from_kwargs(self, **kwargs):
|
||||
"""
|
||||
Generate a deduplication key from the request. The default
|
||||
implementation returns a string based on a stable representation of the
|
||||
input dictionary generated by :py:func:`pprint.pformat`.
|
||||
Generate a deduplication key from the request.
|
||||
"""
|
||||
return pprint.pformat(kwargs)
|
||||
out = []
|
||||
stack = [kwargs]
|
||||
while stack:
|
||||
obj = stack.pop()
|
||||
if isinstance(obj, dict):
|
||||
stack.extend(sorted(obj.iteritems()))
|
||||
elif isinstance(obj, (list, tuple)):
|
||||
stack.extend(obj)
|
||||
else:
|
||||
out.append(str(obj))
|
||||
return ''.join(out)
|
||||
|
||||
def _produce_response(self, key, response):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue