Cms: Multi site issue with tags and assets

Created on 21 Nov 2018  路  7Comments  路  Source: craftcms/cms

We have 130 sites in a multi-site setup.
Some content exists on all sites and some content exists only on 1 site.
Few sites have a lot of their own content - we are talking about tens of thousans of entries with 1 or more Images and 1 or more Tags per each entry.

We were importing that content when we realized that Tags and Assets get created always for every site.
What I mean is that craft_content table has 130 rows for each Tag or Asset element, even though that element exists only on 1 site.
Our database got really big, really fast :)
Both craft_content table and craft_searchindex table would have number of rows in millions if we imported everything.

Is that really how multi-site works with tags and assets?
If yes, can we do something about it, to reduce the size of our database?

We are using single web root for all sites and all sites share the same folders for assets.
Every field is marked as 'Manage relations on a per-site basis'.

Thanks!

Craft Pro 3.0.31

enhancement internationalization

Most helpful comment

We're currently preparing a setup with 12+ Multisite and this feature is desparately missing.
We have about 45,000 Assets in total. That will result in more than half a million database records. Any chance to provide a configuration option for the issue?

All 7 comments

That鈥檚 how it鈥檚 intended to work, yes.

What is your use case that led you to have 130 sites?

Thank you so much for your fast response!

We built city portals in Croatia.
Those sites are 130 Croatian towns.

Is there any way we can make this to not create a row for each Tag and Asset element?

Gotcha. Currently there鈥檚 no way to disable asset/tag multi-site support, unless you were to fork Craft and change the isLocalized() return value from true to false in each of their element classes (craft\elements\Asset and craft\elements\Tag).

We got a similar case with so many sites and it would be really great to disable localized assets. Any possibility for configuration option? An alternative would be #3586.

We're currently preparing a setup with 12+ Multisite and this feature is desparately missing.
We have about 45,000 Assets in total. That will result in more than half a million database records. Any chance to provide a configuration option for the issue?

My solution for this one is i forked the repo and for the element that don't want to propagate i added method to the element class

    public function getSupportedSites(): array
    {
        $sites[] = [
            'siteId' => $this->siteId,
            'enabledByDefault' => 1
        ];

        return $sites;
    }

When i modify the isLocalized to false it hides dropdown on the element index page. I wanted to show dropdown to manage elements as super admin

We're using this patch currently:

--- src/elements/Asset.php  2019-06-04 10:37:54.000000000 +0200
+++ src/elements/Asset.php  2019-07-02 17:33:26.000000000 +0200
@@ -156,7 +156,7 @@
      */
     public static function isLocalized(): bool
     {
-        return true;
+        return false;
     }

     /**

--- src/services/Sites.php  2019-07-03 14:54:25.000000000 +0200
+++ src/services/Sites.php  2019-07-03 14:54:47.000000000 +0200
@@ -796,9 +796,9 @@
             $queue = Craft::$app->getQueue();
             $elementTypes = [
                 GlobalSet::class,
-                Asset::class,
                 Category::class,
                 Tag::class,
             ];

--- src/helpers/ElementHelper.php   2019-07-03 14:54:25.000000000 +0200
+++ src/helpers/ElementHelper.php   2019-07-03 14:54:47.000000000 +0200
@@ -282,7 +282,7 @@
     public static function isElementEditable(ElementInterface $element): bool
     {
         if ($element->getIsEditable()) {
-            if (Craft::$app->getIsMultiSite()) {
+            if (Craft::$app->getIsMultiSite() && $element::isLocalized()) {
                 foreach (static::supportedSitesForElement($element) as $siteInfo) {
                     if (Craft::$app->getUser()->checkPermission('editSite:' . $siteInfo['siteUid'])) {
                         return true;
@@ -307,7 +307,7 @@
         $siteIds = [];

         if ($element->getIsEditable()) {
-            if (Craft::$app->getIsMultiSite()) {
+            if (Craft::$app->getIsMultiSite() && $element::isLocalized()) {
                 foreach (static::supportedSitesForElement($element) as $siteInfo) {
                     if (Craft::$app->getUser()->checkPermission('editSite:' . $siteInfo['siteUid'])) {
                         $siteIds[] = $siteInfo['siteId'];
Was this page helpful?
0 / 5 - 0 ratings