Unable to get all records when doing orderBy

Hello,

I would like to retrieve all my objects sorted by the time they were created but it doesn’t seem possible.

Both in Typescript V1 and oSDK, the ORDER BY filter is tied to the LIMIT filter.

TypeScriptV1:

Lint error on the allAsync() and auto-complete only showing take()

oSDK:

orderBy is only available within the fetchPage block.

    const objects = await client($Objects.MyObject)
      .where({
        objectId: objectId
      })
      .fetchPage({ 
        $pageSize: 1,
        $orderBy: {
          uploadedTimestamp: 'desc'
        }
      })

This seems like a purposeful decision. If this is not a bug, why can’t I get all items after an order call? The entire search result needs to be read from the Ontology anyways in order to sort it, why not give the option to return all records after the sort?

I can sort on the client side but I would much rather leverage the powerful servers backing the Ontology layer to do it for me.

Hi! For TS Functions V1, you should be able to perform .all().sort(…). I.e. retrieve all your objects first, then perform a sort on them based on a property.
For TS Function V2 (which uses osdk), you should be able to add $orderBy: {"<prop>": "asc"} to the args of your asyncIter

.all.sort() is a client side sort. i would like to sort on the server just like i don’t want to filter on the client but on the server

Hi @Bougs,

Your function will throw an error if more than 100,000 objects are loaded from the ObjectSet. Is there a reason why you couldn’t just set takeAsync(100000) in your existing function?

hmm. thats a fair workaround

const result = await Objects.search().MyObject()
                .orderBy(obj => obj.createdAt.desc())
                .takeAsync(this.MAX_TAKE);

but the limitation is on AllAsync as well:

https://www.palantir.com/docs/foundry/functions/api-object-sets/#retrieving-all-objects

why not just give us the function of allAsync() after an orderBy()?

Yes, but if you consider the limitation when using allAsync, it is a much harder limit.

If you had >100k objects, you’d need a way to lower that amount, in order to not have the serverless function crash. This is what take() does in your case, meaning that the number of returned objects won’t crash your function.

You can even use this to implement some pagination in your application, should you need >100k objects in your workflow.

you’re making the argument that allAsync() shouldn’t be used at all, regardless of sorting. That’s fine but separate from what I’m asking about.