Thank you all for your answers.
The general idea is to create a set from a prior search before the main search, which will use it in a “for in/if not in” statement.
The problem (at least… that I thought that I had) is that a search returns me a lazy iterator which will only be loaded if/when asked. When I convert it to a set, it has to load all data to do this.
I tried the following using Anvil Uplink (thanks for the tip @stefano.menci !):
excluded = app_tables.table_b.search() # It took as slow as 1.75s excluded = {b_row['a_row'] for b_row in app_tables.table_b.search()} # Took as slow as 3.4s(!!!), but sometimes as quick as 2.2s. One time it took only 1.8s and another one 10s+. excluded = [b_row['a_row'] for b_row in app_tables.table_b.search()] # Took around 2s~2.5s
The first test was just to compare how quicker would be to get the iterator for all results WITHOUT transforming the results.
The test for sets turned out a little unreliable in terms of time… I could understand why though. I tried passing a tables.order_by parameter to order by ‘a_row’ and it appears to be more quicker and reliable, staying between 2.4 and 3s, but I don’t know if I could take this for certain.
I tested a list since it doesn’t matter if I check for items in [a,b,c,d] that are not in [a,a,a,b,b,b] or that are not in [a,b]: both should give me [c,d].
In my tests, table A has 326 rows and table B has 317 rows.
After this, I tried using the set/list to get rows from table_a that are not in the excluded collection.
What i tried was:
result_list = [a_row for a_row in app_tables.table_a.search() if a_row not in excluded]
I also tried to do a for in loop with the result to compare the time it took from before the main query to after the result of the query and to after the end of the for/in (both counting from before the query).
The results were:
Using the set: ~2.5s to get the set + 1.2s to get the final result
Using the list: ~2.5s to get the list + 1.1s to get the final result
So I gues… it doesn’t really matter. I thought that doing that would be time-costly, since I was going to iterate in all results for both tables.
Thank you all for your help and kindness!
And thank you for the welcoming words, @stefano.menci ! While I’m not new to Anvil and have made a lot of apps here, I’m kind of new to the forum!