from backend.app.db.models.materials import Material from backend.app.db.utils import row2dict from functools import lru_cache @lru_cache(maxsize=128) def get_materials(session): """ This function will retrieve all materials from the database. :return: A list of Material objects if successful, an empty list otherwise. TODO: It might not be the best choice to store the materials data in a database table since thi table probably won't be very large and won't be updated that often. It might be better to store this data in s3 load it into memory when the app starts up. We will test this """ materials = session.query(Material).filter(Material.is_active).all() materials = materials if materials else [] return [row2dict(material) for material in materials]