Due to its utility of returning a Faker instance that's ready to work, faker_create() could potentially be called many times during a single request from different methods.

I recommend static caching the result of faker_create() and returning the cached object if it's already been loaded.

Comments

jrbeeman’s picture

Assigned: jrbeeman » Unassigned
Status: Active » Needs review
StatusFileSize
new547 bytes

First swing at a patch. I've been using this patch successfully on a project that needs to use the Faker library, but isn't utilizing devel_generate. It appears to be working as expected.

jrbeeman’s picture

StatusFileSize
new463 bytes

The previous implementation was too complex. This new patch simplifies the static cache, removing the drupal_static() call seeing as there's no need for other modules to hook into this static cache.

  • baikho committed cd3297d on 7.x-1.x authored by jrbeeman
    Issue #2203671 by jrbeeman: Static cache result of faker_create()
    
baikho’s picture

Status: Needs review » Fixed

Nice, this also helps the usage of unique() modifiers. See https://github.com/fzaninotto/Faker#modifiers

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.