redisco icon indicating copy to clipboard operation
redisco copied to clipboard

Pipelined fetching of multiple objects from ModelSet

Open jkbrzt opened this issue 12 years ago • 4 comments

I've implemented simple pipelined fetching of multiple objects from ModelSet. Not sure if it's useful for others in this form, but you can see the code bellow. For efficiency reason, you can also pass raw=True to get plain dicts instead of model instances.

class ModelSet(Set):

    def get_in_pipeline(self, raw=False):        
        key = self.model_class._key
        ids = list(self._set)
        pipe = self.db.pipeline()

        for id in ids:
            pipe.hgetall('%s:%s' % (key, id))

        for i, hash in enumerate(pipe.execute()):
            id = ids[i]
            if raw:
                hash['_id'] = id
                yield hash
            else:
                model = self.model_class(**hash)
                model._id = id
                yield model

jkbrzt avatar Sep 01 '12 12:09 jkbrzt

I find that globally useful but I'd rather have to configure the modelset to have all operations fetched in a (or in fact two) pipeline(s).

But Redisco should offer such a thing.

kiddouk avatar Sep 05 '12 14:09 kiddouk

So is this going to be merged into the code base?

dmk23 avatar Oct 01 '12 23:10 dmk23

Not yet.

@jkbr and I discussed the need for such a function but I would like something a bit more transparent than another function call on the modelset.

kiddouk avatar Oct 02 '12 09:10 kiddouk

Any progress made on this front? This is almost the only thing missing from redisco. I'd like to be able to do:

foo_list = Foo.objects.get_by_id(ids)

If it pipelined the loading of the objects instead of fetching one by one, that'd be a huge improvement.

72squared avatar Sep 08 '13 14:09 72squared