Sorting RG by Temporarily Calculated Field in Cell (and not in DB)

Hello dear community,

I want to organize my application cleanly and performantly and need your help.

Relevant Database Things:

  • Thing: User
    • Field: Inventory
    • Type: List of Text
  • Thing: Recipe
    • Field: Ingredients
    • Type: Text

Relevant User Actions:

  • Users can add and delete any ingredients (not a static list) to their inventory.
  • Users can create new recipes with any ingredients (not a static list).

Repeating Group Recipes:

  • There is a repeating group where a user sees all recipes (from all users).
  • The “Show all items immediately” checkbox is not checked, and the repeating group loads dynamically because there are many recipes.
  • The data source of the repeating group is a search for recipes (with some filters in the search, so server-side operations only, no client-side filter or sorting).
  • Each cell currently displays the recipe’s preview image and name.

Challenge 1: Display of Available_Ingredients_Count (solved :white_check_mark:):

  • Each cell in the repeating group should show how many ingredients of the recipe the user currently has in their inventory. For example, “3/8” means the user has 3 of the 8 ingredients of the recipe in their inventory and needs to buy 5 more to make the recipe.
  • I currently implemented this with the “Toolbox” plugin using JavaScript in an expression. Code:
  • [Parent group Recipe Ingredients:split by(\n):each item:formatted as JSON-safe:find & replace(",’)].filter(ingredient => [Current Users Inventory:each item:formatted as JSON-safe:find&replace(“,’)].some(user_inventory_item => ingredient.includes.(user_inventory_item)))
  • Accessing Bubble entries in JavaScript is still a bit cumbersome as ":formatted as JSON-safe:find&replace(",’)”.
  • What would be a cleaner way?
  • Unfortunately, I expect ingredients to also include texts containing apostrophes (').

Challenge 2: Filtering and Sorting by Available_Ingredients_Count (Open :question:):

  • Besides, the actual challenge is the following requirement.
  • Users should be able to sort and filter the repeating group by Available_Ingredients_Count.
  • Currently, Available_Ingredients_Count is just a temporarily calculated value not stored in the database.
  • Can I sort the repeating group by a temporarily calculated value that lies in the expression in each individual cell of the repeating group? And as said, the “Show all items immediately” checkbox is not checked.
  • Or do I need Available_Ingredients_Count in the database in the future? But then there would be quite a lot of entries (number of recipes times number of users). And wouldn’t I need to update these entries every time a recipe is created or a user changes their inventory? This approach sounds very workunit-intensive?
  • Does anyone have a good idea?

Performance Requirements:

  • The application must handle several thousand users and tens of thousands of recipes and run efficiently.

I am very grateful for any help :slightly_smiling_face:

Kind regards,
Gero