thank you
I solved the problem with $LinkingMode
But another problem appeared. How to reduce the number of database queries? Where are the 8 queries to the database if I cache the whole template?
In my Page.ss I add next
<% cached 'page', Aggregate(Page).Max(LastEdited), CacheSegment %><!DOCTYPE html>
<html lang="$ContentLocale">
<head>
...
...
</html><% end_cached %>
In mysite/code/Page.php I add a new method in the Controller:
protected function CacheSegment(){
return $_SERVER["REQUEST_URI"];
}
in config.php I have next code
Director::set_environment_type("test");
if(Director::isDev()){ SS_Cache::set_cache_lifetime('any', 3600, 100);
} else { SS_Cache::set_cache_lifetime('any', 3600, 100);
}
Object::add_extension('SiteTree', 'Translatable');
Translatable::set_default_locale('uk_UA');
//global $allowed_locales;
$allowed_locales = array(
'uk_UA',
'ru_RU',
'en_GB'
);
Translatable::set_allowed_locales($allowed_locales);
// enable nested URLs for this site (e.g. page/sub-page/)
SiteTree::enable_nested_urls();
SortableDataObject::add_sortable_classes(array('Foto','Tender','Book','BookNoImg','Slider'));
After these changes the number of queries in the database has decreased to 20 Although I thought that the whole page is cached.
I continued testing and adding in template files next code
SideBar.ss
<% cached 'SideBar', Aggregate(Page).Max(LastEdited), URLSegment %><div class="w220" id="LeftBox">
...
...
</div><% end_cached %>
TopMenu.ss
<% cached 'menu', Aggregate(Page).Max(LastEdited), URLSegment %><div id="TopMenu">
..
..
</div><% end_cached %>
and similarly in all the template files ...
but I will still have 8 database queries
188 Query SET CHARACTER SET 'utf8'
188 Query SET NAMES 'utf8'
188 Init DB antisnid
188 Query SET sql_mode = 'ANSI'
188 Query SHOW TABLES
188 Query SELECT "SiteTree"."ClassName", "SiteTree"."Created", "SiteTree"."LastEdited", "SiteTree"."URLSegment", "SiteTree"."Title", "SiteTree"."MenuTitle", "SiteTree"."Content", "SiteTree"."MetaTitle", "SiteTree"."MetaDescription", "SiteTree"."MetaKeywords", "SiteTree"."ExtraMeta", "SiteTree"."ShowInMenus", "SiteTree"."ShowInSearch", "SiteTree"."HomepageForDomain", "SiteTree"."ProvideComments", "SiteTree"."Sort", "SiteTree"."HasBrokenFile", "SiteTree"."HasBrokenLink", "SiteTree"."Status", "SiteTree"."ReportClass", "SiteTree"."CanViewType", "SiteTree"."CanEditType", "SiteTree"."ToDo", "SiteTree"."Version", "SiteTree"."Priority", "SiteTree"."Locale", "SiteTree"."ParentID", "Page"."ShowSubMenu", "Page"."ShowParentPageLink", "Page"."IntroText", "Page"."HtmlVideoContent", "Page"."HtmlPidmenuLink", "Page"."PhotoID", "NewsPage"."Date", "NewsPage"."NotShowOnHomePage", "SubscriptionPage"."Fields", "SubscriptionPage"."Required", "SubscriptionPage"."CustomisedLables", "SubscriptionPage"."CustomisedErrors", "SubscriptionPage"."NewsletterTypes", "SubscriptionPage"."SubmissionButtonText", "SubscriptionPage"."SendNotification", "SubscriptionPage"."NotificationEmailSubject", "SubscriptionPage"."NotificationEmailFrom", CASE WHEN "SiteTree"."ClassName" IN ('SubscriptionPage') THEN "SubscriptionPage"."OnCompleteMessage" WHEN "SiteTree"."ClassName" IN ('UserDefinedForm', 'SubscribeForm') THEN "UserDefinedForm"."OnCompleteMessage" ELSE NULL END AS "OnCompleteMessage", "ErrorPage"."ErrorCode", "RedirectorPage"."RedirectionType", "RedirectorPage"."ExternalURL", "RedirectorPage"."LinkToID", "VirtualPage"."VersionID", "VirtualPage"."CopyContentFromID", "UserDefinedForm"."SubmitButtonText", "UserDefinedForm"."ShowClearButton", "UserDefinedForm"."DisableSaveSubmissions", "SubscribeForm"."Subscribe", "SubscribeForm"."AllNewsletters", "SubscribeForm"."Subject", "SubscribeForm"."NewletterListTitle", "SiteTree"."ID", CASE WHEN "SiteTree"."ClassName" IS NOT NULL THEN "SiteTree"."ClassName" ELSE 'SiteTree' END AS "RecordClassName" FROM "SiteTree" LEFT JOIN "Page" ON "Page"."ID" = "SiteTree"."ID" LEFT JOIN "NewsPage" ON "NewsPage"."ID" = "SiteTree"."ID" LEFT JOIN "SubscriptionPage" ON "SubscriptionPage"."ID" = "SiteTree"."ID" LEFT JOIN "ErrorPage" ON "ErrorPage"."ID" = "SiteTree"."ID" LEFT JOIN "RedirectorPage" ON "RedirectorPage"."ID" = "SiteTree"."ID" LEFT JOIN "VirtualPage" ON "VirtualPage"."ID" = "SiteTree"."ID" LEFT JOIN "UserDefinedForm" ON "UserDefinedForm"."ID" = "SiteTree"."ID" LEFT JOIN "SubscribeForm" ON "SubscribeForm"."ID" = "SiteTree"."ID" WHERE ("HomepageForDomain" LIKE '%localhost%') AND ("SiteTree"."Locale" = 'uk_UA') ORDER BY "Sort"
188 Query SELECT "SiteTree"."ClassName", "SiteTree"."Created", "SiteTree"."LastEdited", "SiteTree"."URLSegment", "SiteTree"."Title", "SiteTree"."MenuTitle", "SiteTree"."Content", "SiteTree"."MetaTitle", "SiteTree"."MetaDescription", "SiteTree"."MetaKeywords", "SiteTree"."ExtraMeta", "SiteTree"."ShowInMenus", "SiteTree"."ShowInSearch", "SiteTree"."HomepageForDomain", "SiteTree"."ProvideComments", "SiteTree"."Sort", "SiteTree"."HasBrokenFile", "SiteTree"."HasBrokenLink", "SiteTree"."Status", "SiteTree"."ReportClass", "SiteTree"."CanViewType", "SiteTree"."CanEditType", "SiteTree"."ToDo", "SiteTree"."Version", "SiteTree"."Priority", "SiteTree"."Locale", "SiteTree"."ParentID", "Page"."ShowSubMenu", "Page"."ShowParentPageLink", "Page"."IntroText", "Page"."HtmlVideoContent", "Page"."HtmlPidmenuLink", "Page"."PhotoID", "NewsPage"."Date", "NewsPage"."NotShowOnHomePage", "SubscriptionPage"."Fields", "SubscriptionPage"."Required", "SubscriptionPage"."CustomisedLables", "SubscriptionPage"."CustomisedErrors", "SubscriptionPage"."NewsletterTypes", "SubscriptionPage"."SubmissionButtonText", "SubscriptionPage"."SendNotification", "SubscriptionPage"."NotificationEmailSubject", "SubscriptionPage"."NotificationEmailFrom", CASE WHEN "SiteTree"."ClassName" IN ('SubscriptionPage') THEN "SubscriptionPage"."OnCompleteMessage" WHEN "SiteTree"."ClassName" IN ('UserDefinedForm', 'SubscribeForm') THEN "UserDefinedForm"."OnCompleteMessage" ELSE NULL END AS "OnCompleteMessage", "ErrorPage"."ErrorCode", "RedirectorPage"."RedirectionType", "RedirectorPage"."ExternalURL", "RedirectorPage"."LinkToID", "VirtualPage"."VersionID", "VirtualPage"."CopyContentFromID", "UserDefinedForm"."SubmitButtonText", "UserDefinedForm"."ShowClearButton", "UserDefinedForm"."DisableSaveSubmissions", "SubscribeForm"."Subscribe", "SubscribeForm"."AllNewsletters", "SubscribeForm"."Subject", "SubscribeForm"."NewletterListTitle", "SiteTree"."ID", CASE WHEN "SiteTree"."ClassName" IS NOT NULL THEN "SiteTree"."ClassName" ELSE 'SiteTree' END AS "RecordClassName" FROM "SiteTree" LEFT JOIN "Page" ON "Page"."ID" = "SiteTree"."ID" LEFT JOIN "NewsPage" ON "NewsPage"."ID" = "SiteTree"."ID" LEFT JOIN "SubscriptionPage" ON "SubscriptionPage"."ID" = "SiteTree"."ID" LEFT JOIN "ErrorPage" ON "ErrorPage"."ID" = "SiteTree"."ID" LEFT JOIN "RedirectorPage" ON "RedirectorPage"."ID" = "SiteTree"."ID" LEFT JOIN "VirtualPage" ON "VirtualPage"."ID" = "SiteTree"."ID" LEFT JOIN "UserDefinedForm" ON "UserDefinedForm"."ID" = "SiteTree"."ID" LEFT JOIN "SubscribeForm" ON "SubscribeForm"."ID" = "SiteTree"."ID" WHERE ("URLSegment" = 'home' AND "ParentID" = 0) AND ("SiteTree"."Locale" = 'uk_UA') ORDER BY "Sort" LIMIT 1
188 Query SELECT "TranslationGroupID" FROM "SiteTree_translationgroups" WHERE "OriginalID" = 1
188 Query SELECT "SiteTree"."ClassName", "SiteTree"."Created", "SiteTree"."LastEdited", "SiteTree"."URLSegment", "SiteTree"."Title", "SiteTree"."MenuTitle", "SiteTree"."Content", "SiteTree"."MetaTitle", "SiteTree"."MetaDescription", "SiteTree"."MetaKeywords", "SiteTree"."ExtraMeta", "SiteTree"."ShowInMenus", "SiteTree"."ShowInSearch", "SiteTree"."HomepageForDomain", "SiteTree"."ProvideComments", "SiteTree"."Sort", "SiteTree"."HasBrokenFile", "SiteTree"."HasBrokenLink", "SiteTree"."Status", "SiteTree"."ReportClass", "SiteTree"."CanViewType", "SiteTree"."CanEditType", "SiteTree"."ToDo", "SiteTree"."Version", "SiteTree"."Priority", "SiteTree"."Locale", "SiteTree"."ParentID", "Page"."ShowSubMenu", "Page"."ShowParentPageLink", "Page"."IntroText", "Page"."HtmlVideoContent", "Page"."HtmlPidmenuLink", "Page"."PhotoID", "SiteTree"."ID", CASE WHEN "SiteTree"."ClassName" IS NOT NULL THEN "SiteTree"."ClassName" ELSE 'SiteTree' END AS "RecordClassName" FROM "SiteTree" LEFT JOIN "Page" ON "Page"."ID" = "SiteTree"."ID" LEFT JOIN "SiteTree_translationgroups" ON "SiteTree_translationgroups"."OriginalID" = "SiteTree"."ID" WHERE ("SiteTree"."ClassName" IN ('HomePage')) AND ("SiteTree_translationgroups"."TranslationGroupID" = 1 AND "SiteTree"."Locale" = 'uk_UA') GROUP BY "SiteTree"."ClassName", "SiteTree"."Created", "SiteTree"."LastEdited", "SiteTree"."URLSegment", "SiteTree"."Title", "SiteTree"."MenuTitle", "SiteTree"."Content", "SiteTree"."MetaTitle", "SiteTree"."MetaDescription", "SiteTree"."MetaKeywords", "SiteTree"."ExtraMeta", "SiteTree"."ShowInMenus", "SiteTree"."ShowInSearch", "SiteTree"."HomepageForDomain", "SiteTree"."ProvideComments", "SiteTree"."Sort", "SiteTree"."HasBrokenFile", "SiteTree"."HasBrokenLink", "SiteTree"."Status", "SiteTree"."ReportClass", "SiteTree"."CanViewType", "SiteTree"."CanEditType", "SiteTree"."ToDo", "SiteTree"."Version", "SiteTree"."Priority", "SiteTree"."Locale", "SiteTree"."ParentID", "Page"."ShowSubMenu", "Page"."ShowParentPageLink", "Page"."IntroText", "Page"."HtmlVideoContent", "Page"."HtmlPidmenuLink", "Page"."PhotoID", "SiteTree"."ID", CASE WHEN "SiteTree"."ClassName" IS NOT NULL THEN "SiteTree"."ClassName" ELSE 'SiteTree' END ORDER BY "Sort"
110516 13:28:17 188 Query SELECT "SiteTree_Live"."ClassName", "SiteTree_Live"."Created", "SiteTree_Live"."LastEdited", "SiteTree_Live"."URLSegment", "SiteTree_Live"."Title", "SiteTree_Live"."MenuTitle", "SiteTree_Live"."Content", "SiteTree_Live"."MetaTitle", "SiteTree_Live"."MetaDescription", "SiteTree_Live"."MetaKeywords", "SiteTree_Live"."ExtraMeta", "SiteTree_Live"."ShowInMenus", "SiteTree_Live"."ShowInSearch", "SiteTree_Live"."HomepageForDomain", "SiteTree_Live"."ProvideComments", "SiteTree_Live"."Sort", "SiteTree_Live"."HasBrokenFile", "SiteTree_Live"."HasBrokenLink", "SiteTree_Live"."Status", "SiteTree_Live"."ReportClass", "SiteTree_Live"."CanViewType", "SiteTree_Live"."CanEditType", "SiteTree_Live"."ToDo", "SiteTree_Live"."Version", "SiteTree_Live"."Priority", "SiteTree_Live"."Locale", "SiteTree_Live"."ParentID", "Page_Live"."ShowSubMenu", "Page_Live"."ShowParentPageLink", "Page_Live"."IntroText", "Page_Live"."HtmlVideoContent", "Page_Live"."HtmlPidmenuLink", "Page_Live"."PhotoID", "NewsPage_Live"."Date", "NewsPage_Live"."NotShowOnHomePage", "SubscriptionPage_Live"."Fields", "SubscriptionPage_Live"."Required", "SubscriptionPage_Live"."CustomisedLables", "SubscriptionPage_Live"."CustomisedErrors", "SubscriptionPage_Live"."NewsletterTypes", "SubscriptionPage_Live"."SubmissionButtonText", "SubscriptionPage_Live"."SendNotification", "SubscriptionPage_Live"."NotificationEmailSubject", "SubscriptionPage_Live"."NotificationEmailFrom", CASE WHEN "SiteTree_Live"."ClassName" IN ('SubscriptionPage') THEN "SubscriptionPage_Live"."OnCompleteMessage" WHEN "SiteTree_Live"."ClassName" IN ('UserDefinedForm', 'SubscribeForm') THEN "UserDefinedForm_Live"."OnCompleteMessage" ELSE NULL END AS "OnCompleteMessage", "ErrorPage_Live"."ErrorCode", "RedirectorPage_Live"."RedirectionType", "RedirectorPage_Live"."ExternalURL", "RedirectorPage_Live"."LinkToID", "VirtualPage_Live"."VersionID", "VirtualPage_Live"."CopyContentFromID", "UserDefinedForm_Live"."SubmitButtonText", "UserDefinedForm_Live"."ShowClearButton", "UserDefinedForm_Live"."DisableSaveSubmissions", "SubscribeForm_Live"."Subscribe", "SubscribeForm_Live"."AllNewsletters", "SubscribeForm_Live"."Subject", "SubscribeForm_Live"."NewletterListTitle", "SiteTree_Live"."ID", CASE WHEN "SiteTree_Live"."ClassName" IS NOT NULL THEN "SiteTree_Live"."ClassName" ELSE 'SiteTree' END AS "RecordClassName" FROM "SiteTree_Live" LEFT JOIN "Page_Live" ON "Page_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "NewsPage_Live" ON "NewsPage_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "SubscriptionPage_Live" ON "SubscriptionPage_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "ErrorPage_Live" ON "ErrorPage_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "RedirectorPage_Live" ON "RedirectorPage_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "VirtualPage_Live" ON "VirtualPage_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "UserDefinedForm_Live" ON "UserDefinedForm_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "SubscribeForm_Live" ON "SubscribeForm_Live"."ID" = "SiteTree_Live"."ID" WHERE ("URLSegment" = 'home' AND "ParentID" = 0) ORDER BY "Sort" LIMIT 1
188 Query SELECT "SiteConfig"."ClassName", "SiteConfig"."Created", "SiteConfig"."LastEdited", "SiteConfig"."Title", "SiteConfig"."Tagline", "SiteConfig"."Theme", "SiteConfig"."CanViewType", "SiteConfig"."CanEditType", "SiteConfig"."CanCreateTopLevelType", "SiteConfig"."ID", CASE WHEN "SiteConfig"."ClassName" IS NOT NULL THEN "SiteConfig"."ClassName" ELSE 'SiteConfig' END AS "RecordClassName" FROM "SiteConfig" LIMIT 1
188 Quit
where are these requests? for which they are formed, if I try to cache the entire page?