georgringer / news

TYPO3 Extension news
GNU General Public License v2.0
265 stars 355 forks source link

Gateway timeout with relatedByFirstCategory #2156

Closed wowaTYPO3 closed 1 year ago

wowaTYPO3 commented 1 year ago

In TYPO3 12.4.3 and News 11.1.2 I get a gateway timeout in the frontend when I want to output additional news of the same category on the details page as described here: https://docs.typo3.org/p/georgringer/news/main/en-us/Tutorials/BestPractice/IntegrationWithTypoScript/Index.html#show-news-items-with-same-category-in-detail-html

My TypoScript looks like this:

lib.tx_news.relatedByFirstCategory = USER
lib.tx_news.relatedByFirstCategory {
  userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
  extensionName = News
  pluginName = Pi1
  vendorName = GeorgRinger

  settings < plugin.tx_news.settings
  settings {
    relatedView = 1
    detailPid = 31
    limit = 4
    useStdWrap := addToList(categories)
    categories.current = 1
    categoryConjunction = or
    overrideFlexformSettingsIfEmpty := addToList(detailPid)
    startingpoint = 34
  }
}

I have to say that there are about 13000 news articles at the moment, with several new ones added every day.

I work locally with DDEV, and ddev logs shows me the following: NOTICE: PHP message: PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 134217728 bytes) in /var/www/html/vendor/typo3/cms-extbase/Classes/Mvc/Request.php on line 279

However, increasing the PHP memory limit does not help either.

georgringer commented 1 year ago

are you providing several categories? try just one

wowaTYPO3 commented 1 year ago

Hm, I don't quite understand the answer. I'm embedding the object on a page that has a plugin that displays both list and detail view. The news that are displayed there have multiple categories, but it's only about the first one, right?

WebArtAllgaeu commented 1 year ago

the same with the output of news related to similar tags:

lib.tx_news.relatedByTags = USER
lib.tx_news.relatedByTags {
    userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
    extensionName = News
    pluginName = Pi1
    vendorName = GeorgRinger

    settings < plugin.tx_news.settings
    settings {
        # custom tag to use in List.html
        relatedView = 1
        # limit number of news
        limit = 6
# startingpoint = 1

        useStdWrap := addToList(tags)
        tags.current = 1
        categoryConjunction = or
        overrideFlexformSettingsIfEmpty := addToList(detailPid)
        excludeAlreadyDisplayedNews = 1
    }
}

same behavior with single uid or comma separated uid list as string.

P.S: list view and detail view are the same page

typo3 v12.4 DDEV

format-gmbh commented 1 year ago

I have the same problem.

georgringer commented 1 year ago

please use something like this

<f:if condition="{settings.relatedView}">
                <f:else>
                    <f:cObject typoscriptObjectPath="lib.tx_news.relatedByTags">5</f:cObject>
                </f:else>
            </f:if>

and


lib.tx_news.relatedByTags {
settings.relatedView = 1
}
WebArtAllgaeu commented 1 year ago

@georgringer in my typoscript the setting relatedView was already set, but i still get an infinite loop error when i activate xdebug for further investigation:

xdebug output:

(1/1) Error

Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of '1000' frames

at TYPO3\CMS\Extbase\Mvc\Request->getAttribute('extbase', null)

in /var/www/html/vendor/typo3/cms-extbase/Classes/Mvc/Request.php line 271

    {
        return $this->request->getAttributes();
    }

    public function getAttribute($name, $default = null)
    {
        return $this->request->getAttribute($name, $default);
    }

typoscript:

lib.tx_news.relatedByTags = USER
lib.tx_news.relatedByTags {
    userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
    extensionName = News
    pluginName = Pi1
    vendorName = GeorgRinger
    settings < plugin.tx_news.settings
    settings.relatedView = 1
    settings {
        excludeAlreadyDisplayedNews = 1
        limit = 1
        detailPid = 44
        useStdWrap := addToList(tags)
        tags.current = 1
        categoryConjunction = or
        overrideFlexformSettingsIfEmpty := addToList(detailPid)
    }
}

Fluid Snippet:

<f:if condition="{settings.relatedView}">
<f:if condition="{newsItem.tags}">
    <div class="news-related-wrap">
        <h4>
            <f:translate key="related-news"/>
        </h4>
        <div class="news-related news-related-news">
            <f:cObject typoscriptObjectPath="lib.tx_news.relatedByTags">4</f:cObject>
        </div>
    </div>
</f:if>
</f:if>

am i missing something here?

georgringer commented 1 year ago

the cobject should be called if relatedview is NOT set

WebArtAllgaeu commented 1 year ago

@georgringer

my fault. makes sense now.

one question left: what do i need to do to output the related news as list items? currently they are rendered as further detail pages. is this covered in the docs?

georgringer commented 1 year ago

after debugging, I suggest this

lib.tx_news.relatedByTags = USER
lib.tx_news.relatedByTags {
    userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
    extensionName = News
    pluginName = NewsListSticky
    vendorName = GeorgRinger

    mvc {
        callDefaultActionIfActionCantBeResolved = 1
    }
}

so using the NewsListSticky and the mvc setting. if this works, I will adopt the docs

wowaTYPO3 commented 1 year ago

Since I have just (unfortunately ;)) the next 3 weeks vacation, I can only test afterwards. But I give feedback as soon as possible.

georgringer commented 1 year ago

@WebArtAllgaeu to the rescue

format-gmbh commented 1 year ago

For me it runs now with the following settings:

lib.tx_news.relatedByFirstCategory = USER
lib.tx_news.relatedByFirstCategory {
    userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
    extensionName = News
    pluginName = NewsListSticky
    vendorName = GeorgRinger
    settings < plugin.tx_news.settings
    settings {
        relatedView = 1
        detailPid = 123
        useStdWrap := addToList(categories)
        categories.current = 1
        categoryConjunction = or
        overrideFlexformSettingsIfEmpty := addToList(detailPid)
        startingpoint = 1234
    }
}

and

    <f:if condition="{settings.relatedView}">
        <f:else>
            <f:if condition="{newsItem.firstCategory}">
                <f:cObject typoscriptObjectPath="lib.tx_news.relatedByFirstCategory">{newsItem.firstCategory.uid}</f:cObject>
            </f:if>
        </f:else>
    </f:if>
WebArtAllgaeu commented 1 year ago

@georgringer I can confirm that it works with NewsListSticky and mvc setting. just for the case that someone stumbles over this post who has the same problem like me - her is my final typoscript:

lib.tx_news.relatedByTags = USER
lib.tx_news.relatedByTags {
    userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
    extensionName = News
    pluginName = NewsListSticky
    vendorName = GeorgRinger

    mvc {
        callDefaultActionIfActionCantBeResolved = 1
    }

    settings < plugin.tx_news.settings
    settings.hidePagination = 1
    settings.topNewsFirst = 1
    settings {
        relatedView = 1
        excludeAlreadyDisplayedNews = 1
        limit = 3
        detailPid = 44
        useStdWrap := addToList(tags)
        tags.current = 1
        categoryConjunction = or
        overrideFlexformSettingsIfEmpty := addToList(detailPid)
    }
}