[Python] How to Join once in SQLModel for a group of object's Relationships

Discussão em 'Python' iniciado por Stack, Novembro 21, 2024.

  1. Stack

    Stack Membro Participativo

    I am working on a web app where people can run queries on a modest dataset of a few million records. The app is simple, so performance is great, say 100ms to get HTML to the browser. Unless, someone is doing a search which returns many thousands of records and the search result page is doing a foreign key lookup to provide context. In that case, each foreign key lookup is sent to the database as a separate query. Each of which takes a couple milliseconds. And there's a jarring difference in performance as someone stares at a blank screen for seconds wondering what's going on.

    Is there any way to tell sqlmodel that I'm going to be asking for the foreign keys for a list or set of SQLModel objects, and to query the other table once returning many records, rather than querying it many times returning one record each time?

    Of course, I probably should start splitting the results into pages, and figure out some lazy loading, but all of this seems both difficult and a problem many people will encounter, so I presume that I'm just describing it poorly as there must be examples.

    Continue reading...

Compartilhe esta Página