pepkit / pepdbagent

Database for storing sample metadata
BSD 2-Clause "Simplified" License
2 stars 1 forks source link

Add `limit` and `offset` to `pepdbagent.Connection.get_namespace_info()` #57

Closed nleroy917 closed 1 year ago

nleroy917 commented 1 year ago

To support serverside pagination of project information, we need to add a limit and offset parameter to the get_namespace_info() method.

khoroshevskyi commented 1 year ago

I suggest to use search function instead of get_namespace_info(). It will retrieve the same information + function are user specific (retrieving number of samples and projects specific for current user).

56

nleroy917 commented 1 year ago

Hmm. This is a part of this endpoint:

@namespace.get(
    "/",
    summary="View a visual summary of a particular namespace.",
    response_class=HTMLResponse,
)
async def namespace_view(
    request: Request,
    namespace: str,
    db: Connection = Depends(get_db),
    user=Depends(get_user_from_session_info),
    session_info=Depends(read_session_info),
    organizations=Depends(get_organizations_from_session_info),
):
    """Returns HTML response with a visual summary of the namespace."""
    nspace = db.get_namespace_info(namespace, user)
    return templates.TemplateResponse(
        "namespace.html",
        {
            "namespace": nspace,
            "request": request,
            "peppy_version": peppy_version,
            "python_version": python_version(),
            "pephub_version": pephub_version,
            "logged_in": user is not None,
            "session_info": session_info,
            "organizations": organizations,
        },
    )

It would be really nice to just add in limit and offset here instead of making two calls to the database.

nleroy917 commented 1 year ago

Now that I think about it, I think the request will be asynchronous anyways from the client. So, this might not matter. I'll close if this is the case.

khoroshevskyi commented 1 year ago

now if you will run: con.search.namespace_search("Khoroshevskyi", admin_nsp = ('Khoroshevskyi', 'databio',)) or this without admin: con.search.namespace_search("Khoroshevskyi") you will get:

NamespaceSearchModel(number_of_results=1, 
 limit=100, 
 offset=0, 
 results=[
{'namespace': 'Khoroshevskyi',
 'number_of_projects': 4, 
 'number_of_samples': 4
}])

I think, this is everything that you need.

khoroshevskyi commented 1 year ago

is it your issue?