From 16c742990012a38829712fb530986c5e68485a4d Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 9 May 2016 15:39:05 -0400 Subject: [PATCH] Improve interactive performance of 'cd' to slow collections Sometimes a collection will be slow. Don't inflict the 'cd' with the slowness, defer until actually asked to do something that would enumerate said collection. Accomplish this by checking for the 'cd' target in it's parent collection, rather than asking to list its contents. --- confluent_client/bin/confetty | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/confluent_client/bin/confetty b/confluent_client/bin/confetty index be9bbf3d..4c471d2e 100755 --- a/confluent_client/bin/confetty +++ b/confluent_client/bin/confetty @@ -309,11 +309,27 @@ def do_command(command, server): target = fullpath_target(argv[1], forcepath=True) else: # cd by itself, go 'home' target = '/' - for res in session.read(target, server): - if 'errorcode' in res: - exitcode = res['errorcode'] - if 'error' in res: - sys.stderr.write(target + ': ' + res['error'] + '\n') + if target[-1] == '/': + parentpath = target[:-1] + else: + parentpath = target + if parentpath: + childname = '{0}/'.format(parentpath[parentpath.rindex('/') + 1:]) + parentpath = parentpath[:parentpath.rindex('/') + 1] + foundchild = False + for res in session.read(parentpath, server): + try: + if res['item']['href'] == childname: + foundchild = True + except KeyError: + pass + if 'errorcode' in res: + exitcode = res['errorcode'] + if 'error' in res: + sys.stderr.write(target + ': ' + res['error'] + '\n') + target = otarget + if not foundchild: + sys.stderr.write(target + ': Target not found - \n') target = otarget elif argv[0] in ('cat', 'show', 'ls', 'dir'): if len(argv) > 1: