Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small optimization in collectNewsImages #9

Closed
fritzmg opened this issue Apr 1, 2015 · 3 comments
Closed

Small optimization in collectNewsImages #9

fritzmg opened this issue Apr 1, 2015 · 3 comments
Labels

Comments

@fritzmg
Copy link
Contributor

fritzmg commented Apr 1, 2015

Since the news modules already provide the actual path to the image file via the singleSRC variable of the template, a small optimization can be done in collectNewsImages :). This code:

$objFile = \FilesModel::findByPk($arrData['singleSRC']);

if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path))
{
    $GLOBALS['SOCIAL_IMAGES'][] = $objFile->path;
}

could be replaced by

if (is_file(TL_ROOT . '/' . $objTemplate->singleSRC))
{
    $GLOBALS['SOCIAL_IMAGES'][] = $objTemplate->singleSRC;
}

and thus saves a database query.

@qzminski
Copy link
Member

qzminski commented Apr 1, 2015

Two questions:

  1. Are you sure the query is executed? The model should be already there in the model registry.
  2. Are you sure that $objTemplate->singleSRC contains the path to full image and not to the thumbnail?

@fritzmg
Copy link
Contributor Author

fritzmg commented Apr 1, 2015

  1. Are you sure the query is executed? The model should be already there in the model registry.

I haven't checked, but you are right of course, the result could already be in the model registry.

  1. Are you sure that $objTemplate->singleSRC contains the path to full image and not to the thumbnail?

Yes, $objTemplate->singleSRC always contains the path to the full image (i.e. the image selected in your news entry), while $objTemplate->src contains the path to the thumbnail (or in Contao 3.4.x and onwards it is stored within $objTemplate->picture iirc).

@qzminski
Copy link
Member

qzminski commented Apr 1, 2015

I think we can assume the model is already registered because of this line:

https://github.com/contao/core/blob/master/system/modules/news/modules/ModuleNews.php#L149

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants