Skip to content

Commit

Permalink
fix logic filtering smart stacks
Browse files Browse the repository at this point in the history
prior implementation was incorrect and after testing learned SMARTSTACK
represents an unique id for smart stack images. Changed logic to mimic
frontend implementation of removing intermediates. Creating a dict of
max stknum smart stacks and then using list comprehension to build a new
list of only the max stknums and non smart stack images. Tested and working
properly.
  • Loading branch information
LTDakin committed Nov 28, 2023
1 parent 9f235bb commit f67cda7
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions api/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,34 @@ def filtered_images_query(db_address: str, query_filters: list):
.all()
session.expunge_all()
image_pkgs = [image.get_image_pkg() for image in images]
image_pkgs = list(filter(filter_img_pkgs_final_sstack, image_pkgs))
image_pkgs = filter_img_pkgs_final_sstack(image_pkgs)
return image_pkgs

# Filter smart stacks to reduce the size of ui payload
def filter_img_pkgs_final_sstack(img_pkg):
try:
if img_pkg["SMARTSTK"] == 'no' or img_pkg["SMARTSTK"] == img_pkg["SSTKNUM"]:
return True
return False
except KeyError :
return True
def filter_img_pkgs_final_sstack(image_pkgs):
# dict containing max stknum for each unique smartstack
max_sstk_nums = {}

for img_pkg in image_pkgs:
smart_stk = img_pkg.get('SMARTSTK')
sstk_num = img_pkg.get('SSTKNUM')

if smart_stk is None or smart_stk == 'no':
continue

if smart_stk not in max_sstk_nums or sstk_num > max_sstk_nums[smart_stk]:
max_sstk_nums[smart_stk] = sstk_num

# keep non intermediate img_pkgs, non smart stack img_pkgs, and img_pkgs missing smart stack keys
filtered_arr = [
img_pkg for img_pkg in image_pkgs
if img_pkg.get('SMARTSTK') is None
or img_pkg.get('SSTKNUM') is None
or img_pkg.get('SMARTSTK') == 'no'
or img_pkg['SSTKNUM'] >= max_sstk_nums.get(img_pkg.get('SMARTSTK'), 0)
]

return filtered_arr

def get_image_by_filename(db_address, base_filename):
"""Gets the image package for the image specified by the filename.
Expand Down

0 comments on commit f67cda7

Please sign in to comment.