diff options
author | Frederick Muriuki Muriithi | 2025-06-11 15:32:35 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-06-11 15:32:35 -0500 |
commit | fd69f9bc98e730664c4a1c64a095e08c83acf1a3 (patch) | |
tree | 2b93a3ce60d68c55dc9f63fc95abe59dab290c9b /uploader/publications/models.py | |
parent | 78217b0a98b475af1596ab5d8300e9a85ea72b65 (diff) | |
download | gn-uploader-fd69f9bc98e730664c4a1c64a095e08c83acf1a3.tar.gz |
Limit returned results
Limit the number of results returned to make page more
responsive. This is buggy at this point — it doesn't do exactly what I
expect, e.g. when I attempt to scroll, or use pagination, it doesn't
actually display all the pages as expected.
Diffstat (limited to 'uploader/publications/models.py')
-rw-r--r-- | uploader/publications/models.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/uploader/publications/models.py b/uploader/publications/models.py index 992ebfa..f4e8d33 100644 --- a/uploader/publications/models.py +++ b/uploader/publications/models.py @@ -71,16 +71,23 @@ def update_publications(conn: Connection , publications: tuple[dict, ...]) -> tu def fetch_publications( conn: Connection, - search: Optional[str] = None + search: Optional[str] = None, + offset: int = 0, + limit: int = -1 ) -> Iterable[dict]: """Fetch publications from the database.""" _query = "SELECT * FROM Publication" _params = None if search is not None and bool(search): _query = (f"{_query} " - "WHERE CONCAT(PubMed_ID, ' ', Authors, ' ', Title) " - "LIKE %s") - _params = (f"%{search}%",) + "WHERE PubMed_ID LIKE %s " + "OR Authors LIKE %s " + "OR Title LIKE %s") + _params = (f"%{search}%",) * 3 + + if limit > 0: + _query = (f"{_query} LIMIT {limit} OFFSET {offset}") + with conn.cursor(cursorclass=DictCursor) as cursor: cursor.execute(_query, _params) debug_query(_query, logger) |