Symfony3 Controller loading time - symfony

I have a question.
Where could be a problem when my controller loading speed is sometime 1800ms?
Here is controller code:
Is here some way to write this code better?
Thanks

Ok, by experience since the version 3 of symfony, Assetic slow considerably considerably the time of load of a page in environment of "dev".
I think that that your problem comes from the Assetic bundle..
I propose an alternative solution :
Deactivate "Assetic" and pass by other alternative solutions: https://symfony.com/doc/current/cookbook/assetic/index.html
Or return to the simple include of the files js/css/img/... with the 'asset' function twig {{ asset('js/script.js') }}

Just a suggestion, also save the getRepository instance in some variable, good practice and will reduce speed but not enough.

Is here some way to write this code better?
It's not the source of your problem.
For me cache configuration was the key to solve such a problem.
php.ini settings (win)
zend_extension=php_opcache.dll
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=0
opcache.fast_shutdown=1
opcache.enable_cli=1
realpath_cache_size = 4096k

Related

Nelmio/Alice 2.x Symfony 3 , Loading Related Fixtures in Different Bundles

If there's already answer to my question then sorry and please point me in the right direction because I can't find anything.
Let's say I have two Bundles. Each bundle has fixures.yml file and loader file.
Loaders and fixtures are working fine when they are not depending on each other.
However when I am referencing fixtureA from fixtureB I get duplicated record in database.
E.g:
user_{1..10}:
email (unique): '<firstName()>+<randomNumber()>#gmail.com'
plainPassword: 'secret'
story_{1..10}:
user: "#user_<current()>"
title: '<word>'
When they are in separated files - duplicated row. When they are in the same file everything is ok.
Why it's being loaded twice?
I even tried this:
$objects = Fixtures::load(__DIR__ . '/fixtures.yml', $manager, ['persist_once'=>true]);
No luck.
Evey time I am trying to use user object in story fixtures alice tries to save it into db again.
Best Regards,
Robert
I did a little research and talked to people - it looks like it's a possible bug. You can learn more here:
Nelmio/Alice 2.x Duplicated Row
Also I would like to share my work around:
I wanted to keep things separated and clean. Instead of keeping all fixtures in one file in one bundle you can move it to App/DataFixtures/ORM directory. However Symfony will not look for fixtures in this directory. You can:
add path to the fixtures in console command:
doctrine:fixtures:load --fixtures=/var/www/story/app/DataFixtures/ORM
create alias for above solution
override DoctrineFixturesBundle - how to do this
I hope this will help if you have similar issue.

Override DS default layout

Using Drupal 8
I need to override the default DS "One Column Layout".To do that I use the suggested template name: ds-1col--tools-tools.html.twig . I have placed that file in various locations and then cleared cache but Drupal never picks up on it:
mytheme/templates/ds
mytheme/ds_layouts/templates/
mytheme/templates/ds_layouts/
mytheme/templates/
None of this places work, what could I possibly be doing wrong?
Through a comment from #Matoeil , I looked through Twig Debug's suggestions and they suggested a different kind of name for the file. When using Twig debugs suggestion, it recognized it right away.
So I suppose the suggestions made by Display Suite don't seem to work very well.

mopabootstrap fosuserbundle translation labels

I cant get the form_widget (from mopabootstrapbundle) to use the translation (from FOSUserBundle) to work in the registration form (from FOSUserBundle) after extending it to my bundle.
https://github.com/phiamo/MopaBootstrapBundle/issues/8
my problem is the same as the above issue, but I cannot understand how it is solved.
I guess I must somehow use the translation_domain from FOSUserBundle
did you make all the steps as on this post: https://github.com/phiamo/MopaBootstrapBundle/issues/8#issuecomment-2842368 and especially lines:
copied the whole templates dir from views/Registration to
app/FosUserBundle/views/Registration/
This is the way I dealt with my problem
https://github.com/phiamo/MopaBootstrapBundle/issues/8

Webservlet urlpatterns for index.jsp

I'm stuck with this problem and I can't find a solution for it anywhere, so any ideas are welcome.
I want to execute some code on a #WebServlet (javax.servlet.annotation.WebServlet) before it loads my index.jsp. For that I added "/" to the urlPatterns. This does what it's expected in the index.jsp, but it doesn't load my css or image paths any more. The problem is the "/" makes it include all other files in these urlPatterns, but if I try to use "index" instead, it doesn't work.
Can someone please help?
Cheers,
M.
Just use an url-pattern which exactly matches /index.jsp.
#WebServlet(urlPatterns = { "/index.jsp" })
Unrelated to the concrete question, I wonder if you can't better use a ServletContextListener (which is annotable using #WebListener). This is certainly true when your sole functional requirement is to preload/preinitialize some application-wide data on server's startup, regardless of the first-opened webpage.

How to work with hook_nodeapi after image thumbnail creation with ImageCache

A bit of a followup from a previous question.
As I mentioned in that question, my overall goal is to call a Ruby script after ImageCache does its magic with generating thumbnails and whatnot.
Sebi's suggestion from this question involved using hook_nodeapi.
Sadly, my Drupal knowledge of creating modules and/or hacking into existing modules is pretty limited.
So, for this question:
Should I create my own module or attempt to modify the ImageCache module?
How do I go about getting the generated thumbnail path (from ImageCache) to pass into my Ruby script?
edit
I found this question searching through SO...
Is it possible to do something similar in the _imagecache_cache function that would do what I want?
ie
function _imagecache_cache($presetname, $path) {
...
...
// check if deriv exists... (file was created between apaches request handler and reaching this code)
// otherwise try to create the derivative.
if (file_exists($dst) || imagecache_build_derivative($preset['actions'], $src, $dst)) {
imagecache_transfer($dst);
// call ruby script here
call('MY RUBY SCRIPT');
}
Don't hack into imagecache, remember every time you hack core/contrib modules god kills a kitten ;)
You should create a module that invokes hook_nodeapi, look at the api documentation to find the correct entry point for your script, nodeapi works on various different levels of the node process so you have to pick the correct one for you (it should become clear when you check the link out) http://api.drupal.org/api/function/hook_nodeapi
You won't be able to call the function you've shown because it is private so you'll have to find another route.
You could try and build the path up manually, you should be able to pull out the filename of the uploaded file and then append it to the directory structure, ugly but it should work. e.g.
If the uploaded file is called test123.jpg then it should be in /files/imagecache/thumbnails/test123/jpg (or something similar).
Hope it helps.

Resources