Be warned, there will be some Python programming stuff; my problem is tightly connected to database engine differences though - or at least I think so.

tl;dr: Querying for list of items and all photos connected to them takes a second or two on sqlite, a minute or two on mySQL on Amazon RDS. What's the typical overhead of using remote database solution?

My application stores multiple (and variable number of) images per product. Obvious solution is one-to-many relationship between product and its images. The Django models look like this:

class Product(models.Model):
    (other stuff here...)

class ProductImage(models.Model):
    product = models.ForeignKey(Product) 
    url = models.URLField()

( index is generated for all key fields automatically )

In application, I need to send over a partial list of products as JSON. It looks like this:

data = Product.objects.filter(filtering criteria go there)
data_json = [ item.to_dict() for item in data ]

Which in turn calls to_dict function defined in my model:

def to_dict(self):
    images = self.productimage_set.all()
    imagelist = []
    for image in images:

    return {
        (other stuff...)
        'images': imagelist

So, for every item retrieved, I'm asking for images connected to it. While on sqlite3, this process was pretty much instantenous. After moving to Amazon's RDS, the filtering part takes 2-5s, the 'imagelist' generation up to two minutes. Any ideas what's happening?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.