def patch_query_execute():
    real_execute = peewee.Query._execute
    real_clone = peewee.Query.clone

    @wraps(real_execute)
    def metered_execute(self, *args, **kwargs):
        name = self.model_class.__name__

        action = getattr(self, 'model_action', 'unknown')

        start_time = time.time()
        try:
            result = real_execute(self, *args, **kwargs)
            return result
        finally:
            duration = (start_time - time.time()) * 1000
            statsd_client.timing('db.{}.{}'.format(name, action), duration)
            metrics_logger.debug("model=%s query=%s duration=%.2f", name, action, duration)

    @wraps(real_clone)
    def extended_clone(self):
        cloned = real_clone(self)
        setattr(cloned, 'model_action', getattr(self, 'model_action', 'unknown'))
        return cloned

    peewee.Query._execute = metered_execute
    peewee.Query.clone = extended_clone
dataset/ETHPy150Open getredash/redash/redash/metrics/database.py/patch_query_execute/swapped operands of `-`