3
votes

I'm new to Symfony and take over Symfony 1.4 (Propel ORM) project in the company from someone who resigned with immediate effect.

I went through jobeet tutorial and generally comfortable to Symfony. Now project is about to finish but when I see logs, I find lot of queries running for every single page. On lot of pages, queries are running within loops. As per my experience, no SQL query should run in loop.

This left me worried about post release performance of the project.

In jobeet tutorial or else where, I didn't find much about database optimization using symfony 1.4/propel. Is there any good tutorial/guidelines about database and performance optimization for Symfony 1.4 (with propel)

From where, should I start with optimization phase. I'm basically interested to know few links and how other experienced symfony developers optimize their projects.

1
If you having memory issue, you check this french post.j0k
This old blog post about Propel Queries is a good start. Basically, reducing the amount of queries is easy with Propel. You just have to use "joinWith()" instead of just "join()". SQL in loops is often a bad idea, try to fetch your data before.William Durand

1 Answers

1
votes

I'm willing to bet (from my experience with Symfony 1.*) that the problem has to do with Propel's poor support for joins. They've actually improved this in more recent versions but if you're using Criteria or Peer classes, then that's a good indication you're using an older version and you will run into this problem.

Say you perform a query to retrieve a bunch of records from the database. If that table has a one-to-many relationship with another table, you need to perform a separate query to retrieve those associated records. If you have a many-to-one or a one-to-one relationship, that process can be made a lot more efficient by using the "doSelectJoin" peer methods.

I probably need to give you an example: Let's say you have a online book store and in your schema you have 3 tables: books, authors and publishers:

  1. A book can have multiple authors.
  2. A book can only have one publisher.

If you perform a query on the book table to retrieve all book objects. You can use the "doSelectJoin" methods to return all the book objects and no extra queries are required to retrieve their associated publisher. These will come hydrated with book i.e. $book->getPublisher() won't perform another query. However, if you want to get the authors associated with that book. Then the first time you call the function $book->getAuthors(), a separate query will run (Subsequent calls to the getAuthor method on the same object will lazy load the associated author objects and not require another query). But if you're displaying 50 books on a page, then you'll need to perform another 50 queries if you want to display the books' authors as well.