QutEcoacoustics / baw-server

The acoustic workbench server for storing and managing ecoacoustic data. Manages the structure and audio data. Provides an API for clients access.
Apache License 2.0
9 stars 4 forks source link

Harvest Items directory listing is returning incorrect results #595

Closed atruskie closed 2 years ago

atruskie commented 2 years ago

It looks like the paging filters (take and limit) are applied to the base query before the directory projection is applied.

The net result is that when there are many harvest items, so much so, the first page only contains entries from one directory, only one directory result ends up being shown.

The paging needed to be applied after the directory query.

Repro: in a harvest with 317 files across three directories...

GET https://api.staging.ecosounds.org/harvests/25/items?page=1 returns

{
    "meta": {
        "status": 200,
        "message": "OK",
        "sorting": {
            "order_by": "id",
            "direction": "asc"
        },
        "paging": {
            "page": 1,
            "items": 25,
            "total": 317,
            "max_page": 13,
            "current": "http://api.staging.ecosounds.org/harvests/25/items?direction=asc&items=25&order_by=id&page=1",
            "previous": null,
            "next": "http://api.staging.ecosounds.org/harvests/25/items?direction=asc&items=25&order_by=id&page=2"
        }
    },
    "data": [
        {
            "id": null,
            "path": "CLUSTER",
            "validations": null
        }
    ]
}

Whereas GET https://api.staging.ecosounds.org/harvests/25/items?page=2 returns

{
    "meta": {
        "status": 200,
        "message": "OK",
        "sorting": {
            "order_by": "id",
            "direction": "asc"
        },
        "paging": {
            "page": 2,
            "items": 25,
            "total": 317,
            "max_page": 13,
            "current": "http://api.staging.ecosounds.org/harvests/25/items?direction=asc&items=25&order_by=id&page=2",
            "previous": "http://api.staging.ecosounds.org/harvests/25/items?direction=asc&items=25&order_by=id&page=1",
            "next": "http://api.staging.ecosounds.org/harvests/25/items?direction=asc&items=25&order_by=id&page=3"
        }
    },
    "data": [
        {
            "id": null,
            "path": "CLUSTER",
            "validations": null
        },
        {
            "id": null,
            "path": "HOUSE",
            "validations": null
        }
    ]
}

Neither of these results are correct. Also note: the paging values are incorrect.