Friday, December 7, 2012

Bundle for faster generation of entity dropdowns for Symfony 2

Soon after writing my previous blog, where I described a way to speed up the rendering of entity dropdowns, I received lots of feedback about better and nicer ways of doing this. All the suggestions where the same: use a custom form type and a datatransformer.

So I did for one entity, but I didn't feel like doing it for every entity. So I wrote a console command that allowed me to do this automatically (for one or all entities within a bundle).

After a short discussion with my boss, we agreed upon releasing the generator to the public and today the day is here.

The bundle is located at https://github.com/TheDevilOnLine/Symfony-FastEntityBundle and can be installed via composer. For all the details please take a look at https://github.com/TheDevilOnLine/Symfony-FastEntityBundle/blob/master/README.md

Oh and feel free to say thanks to my boss (Martijn) in the comments, for allowing me to opensource otherwise proprietary code.

P.S. This is my first time releasing code using composer, so please report any bugs you might run in to on GitHub: https://github.com/TheDevilOnLine/Symfony-FastEntityBundle/issues

3 comments:

  1. Nice idea, but you code don't match the standards of good quality code.

    1. You generate classes with a lot of copy & paste code. To fix that create abstract class providing all logic and requiring implementation of abstract methods: getEntityName(), getKeyFieldName(), getFieldName(). This'll simply future improvements and bug fixes
    2. Even better will be creating services for transformer and form type taking in a constructor parameter object holding all required data - on data source
    3. Following point 2 you can have single implementation of form type and transformer (not abstract), customized by service parameters (less code, less maintenance)

    ReplyDelete
  2. Also if you say "faster" - please provide numbers. Otherwise this word is meaningless.

    ReplyDelete
    Replies
    1. Hey Maciej,

      thanks for your feedback, now that you mention it, I totally agree with you.

      About the numbers, I already mentioned those in the preceding blog: http://12wiki.blogspot.nl/2012/11/speeding-up-rendering-of-entity.html - With the 'entity' field used (with about 1000 entities), the rendering of the form takes about 2 seconds (1977ms to be exact). Using this code will reduce the time to 310-340 ms. So that's a 6-7x speed-up!
      Cheers,
      Tom

      Delete