From 3738a60195df3b376f8f3c875047dcce99100c4b Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 28 Sep 2020 14:22:28 -0700 Subject: [PATCH] Cache photodbs throughout runtime. --- frontends/etiquette_cli.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frontends/etiquette_cli.py b/frontends/etiquette_cli.py index 41365a8..0f0e33b 100644 --- a/frontends/etiquette_cli.py +++ b/frontends/etiquette_cli.py @@ -8,15 +8,23 @@ import etiquette class CantFindPhotoDB(Exception): pass +photodbs = {} + def find_photodb(): path = pathclass.cwd() + while True: + try: + return photodbs[path] + except KeyError: + pass if path.with_child('_etiquette').is_dir: break if path == path.parent: raise CantFindPhotoDB() path = path.parent photodb = etiquette.photodb.PhotoDB(path.with_child('_etiquette'), create=False) + photodbs[path] = photodb return photodb def search_argparse(args):