Model design for aggregates/counts

Hello all,

I’m building a page that’ll contain a table of aggregate data by “location”. I.e. total number of assets and the total value of said assets per location etc. A user can click on a table row to get the assets for said location as a list. I’m of course planning on modeling out my Assets but I wanted to know how the community generally handles pulling just aggregate data on said model.

Through Metadata on the Asset model? Maybe a separate model just for this data? Perhaps a model for my Locations that contains the aggregate data?

/assets/?location=my-location&aggregate=price,count?
/locations/assets/?aggregate=price,count?

Pretty sure this is a standard thing to do and wanted some feedback from those who’ve done it before.

Thanks!

My first instinct (and how I’ve seen others do it) is a dedicated aggregates endpoint that the app can consume.

Also an option for larger data is to have a query which only returns ids. Then as needed with pagination batch fetch by passing the set of ids to the entity endpoint.

Yup that’s what I would do as well. I didn’t clarify what I was asking well enough, sorry.

My question is more around how to manage the storage of said information. I suppose the most straight forward way, and easiest to maintain, would be a model that stored said aggregate information. Then I could update it in the background if I desired once the user requests the full list of assets belonging to a location to keep itself in sync.

Thanks

1 Like