From: tierno Date: Mon, 9 Jan 2017 11:46:17 +0000 (+0100) Subject: avoid image duplication of public images referenced by several tenants X-Git-Tag: v1.0.4~3 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2Fopenvim.git;a=commitdiff_plain;h=12cb90b1ca94a74962248066048b47e3311983ec avoid image duplication of public images referenced by several tenants Signed-off-by: tierno --- diff --git a/httpserver.py b/httpserver.py index ce433ae..abbeddd 100644 --- a/httpserver.py +++ b/httpserver.py @@ -1046,7 +1046,7 @@ def http_get_images(tenant_id): else: from_ ='tenants_images right join images on tenants_images.image_id=images.uuid' where_or_ = {'tenant_id': tenant_id, 'public': 'yes'} - result, content = my.db.get_table(SELECT=select_, FROM=from_, WHERE=where_, WHERE_OR=where_or_, WHERE_AND_OR="AND", LIMIT=limit_) + result, content = my.db.get_table(SELECT=select_, DISTINCT=True, FROM=from_, WHERE=where_, WHERE_OR=where_or_, WHERE_AND_OR="AND", LIMIT=limit_) if result < 0: print "http_get_images Error", content bottle.abort(-result, content) @@ -1073,7 +1073,7 @@ def http_get_image_id(tenant_id, image_id): from_ ='tenants_images as ti right join images as i on ti.image_id=i.uuid' where_or_ = {'tenant_id': tenant_id, 'public': "yes"} where_['uuid'] = image_id - result, content = my.db.get_table(SELECT=select_, FROM=from_, WHERE=where_, WHERE_OR=where_or_, WHERE_AND_OR="AND", LIMIT=limit_) + result, content = my.db.get_table(SELECT=select_, DISTINCT=True, FROM=from_, WHERE=where_, WHERE_OR=where_or_, WHERE_AND_OR="AND", LIMIT=limit_) if result < 0: print "http_get_images error %d %s" % (result, content) diff --git a/vim_db.py b/vim_db.py index 11a7aa1..a458a8e 100644 --- a/vim_db.py +++ b/vim_db.py @@ -218,10 +218,14 @@ class vim_db(): 'WHERE_OR': dict of key:values, translated to key=value OR ... (Optional) 'WHERE_AND_OR: str 'AND' or 'OR'(by default) mark the priority to 'WHERE AND (WHERE_OR)' or (WHERE) OR WHERE_OR' (Optional) 'LIMIT': limit of number of rows (Optional) + 'DISTINCT': make a select distinct to remove repeated elements Return: a list with dictionarys at each row ''' #print sql_dict - select_= "SELECT " + ("*" if 'SELECT' not in sql_dict else ",".join(map(str,sql_dict['SELECT'])) ) + select_ = "SELECT " + if sql_dict.get("DISTINCT"): + select_ += "DISTINCT " + select_ += ("*" if 'SELECT' not in sql_dict else ",".join(map(str,sql_dict['SELECT'])) ) #print 'select_', select_ from_ = "FROM " + str(sql_dict['FROM']) #print 'from_', from_