Ticket (Solved)

how do I iterate through content parts

I have a medium sized set of content parts (say 10k) that I would like to iterate through without bringing them all into memory all at once. How can I fetch them one at a time or do some other trick that makes reading lots of content parts fast and less memory intensive?

Re: how do I iterate through content parts

You can specify a query when retrieving the parts:

var mylist = _contentManager.Query<SomePart, SomePartRecord>().Where(p=>p.Age > 10).List();

This would bring back a subset that you could iterate thru further in memory:

Or you could bring back records one at a time with something like:

var mypart = _contentManager.Get(id);

and wrap this in a loop. But be warned that this is very slow and would be unusable if you had 10,000 records to loop through.

Monday, September 8, 2014 9:26:32 AM bydavegardner

Re: how do I iterate through content parts

Right now I am using the _contentManager.Query. I guess I should be looking for examples where people are paging through data using _contentManager.Query? Thoughts?

Monday, September 8, 2014 11:13:57 PM byRob Allred

Re: how do I iterate through content parts

Have a look at the AdminController of the Contents module - you'll see how Paging is implemented, and how you can perform pages queries (I think using a Slice method on a ContentQuery object, which you get from _contentManager.Query() if I'm not mistaken).

Friday, September 12, 2014 1:15:35 AM bysfmskywalker

Post a reply

You need to be signed in to post a reply.

Sign In