I was reading this nice thread with very Pythonic posts, and wonder a few things:
Is there is a rule-of-thumb on the number of rows returned for every increment of q.page_size(n)? I notice (in my basic testing) that when I apply that directive on .search() calls initiated from backend code, I get 10 rows; and that’s whether I specify q.page_size(10) or q.page_size(1). It’s pop-up documentation indicates rows returned, but I’m wondering if it really is something more like memory-pages. Then again, it may be because I’m launching .search() from backend code, not the frontend code (so maybe it doesn’t apply there – I’m unsure).
My follow-on question, then, is how to stream .search() results from the backend to the frontend? I haven’t thought about this, but a naive approach might be to get the complete list of row_ids (a list() of strings) for a given .search(), and iterate through the ids (chunks at a time), blacklisting the previous ones retrieved. I’m sure there’s something more elegant.
These two questions arise because right now I’m invoking anvil.server.call() from the Client to a Server module that actually runs the .search(). (I thought that might be more secure). But I don’t know how to stream rows on Anvil that way.
(PS: Sorry that I interchanged Frontend & Backend with Client & Server, respectively).
A search iterator by default, will fetch more results as needed when you iterate over it on the client side. To me, that’s streaming, and it’s automatic. So I’m assuming that you mean something different that I’m not thinking of.
Thank you. Yes, what you described sound like streaming to me, as well. Tomorrow let me examine my code and my question again (which was somewhat of a run-on) to see if I can word it better. Perhaps I’ll type in some code snippets. Thank you.
Let me replay what you said to see if it lines up.
Let’s say I have a Data Table that Client code cannot interact with at all (restricted as such in the IDE); however Server code can search it. Thus, from Client code I’ll launch a search of that table via a anvil.server.call() to code in a Server module which actually performs the search and receives its results object (I guess the search iterator). If I subsequently return that search iterator object back to the Client (which again is otherwise restricted from interacting with the Data Table), will the Client be able to freely interact with that object (the search iterator), as you described. For example, interate, subscript (like a list), random.choice() from it, etc.
You spoke with me about this previously and I’ll look it up when I get home (that particular conversation was along the lines of being able to randomly select items in search results objects and how paging might be involved), so my apologies for the repeat and clarification. Thank you.
Yes. The client will not be able to modify the contents (unless you return a client writable view), but the client can otherwise read the search results just the same as the server would.