OrchardCMS / Orchard

Orchard is a free, open source, community-focused Content Management System built on the ASP.NET MVC platform.
https://orchardproject.net
BSD 3-Clause "New" or "Revised" License
2.38k stars 1.12k forks source link

If you reselect n times a theme based on another one, the ShellFeature table grows up by 2 power n (small fix included) #4940

Open orchardbot opened 9 years ago

orchardbot commented 9 years ago

@jtkech created: https://orchard.codeplex.com/workitem/21111

Somebody was concerned by this issue, see http://www.orchardpros.net/tickets/4683 He had a ShellFeature table of 200000 rows and cache.dat size of about 3 Mb

The fix is to enable the theme and the base theme in one pass

In ThemeService.cs, in EnableThemeFeatures() method

Replace
while (themes.Count > 0) _featureManager.EnableFeatures(new[] {themes.Pop()});

With if (themes.Count > 0) // Evolutive _featureManager.EnableFeatures(themes.ToList());

Note: Same kind of fix to do in DisableThemeFeatures()

In case of this can be caused by another source, I propose another fix with these benefits With 1) and 2), the internal features list in memory has always only distinct features With 1), by enabling / disabling a feature, a clean table and cache.dat are regenerated

1) In ShellDescriptorManager.cs, in GetShellDescriptorFromRecord() method

Replace
descriptor.Features = descriptorFeatures;

With descriptorFeatures = descriptorFeatures.GroupBy(x => x.Name).Select(g => g.First()).ToList();

2) In ShellDescriptorCache.cs, in GetShellDecriptorForCacheText() method

Replace
shellDescriptor.Features = features.Select(feature => new ShellFeature { Name = feature }).ToList();

With shellDescriptor.Features = features.Select(feature => new ShellFeature { Name = feature }) .GroupBy(x => x.Name).Select(g => g.First()).ToList();

orchardbot commented 9 years ago

@jtkech commented:

Update

In the Replace section of 1) Change descriptorFeatures = ... with descriptor.Features = ...

Sorry

Note :The person on orchardpros.net seems to have others symptoms. So I'm not sure for the fixes. I will investigate. But the symptoms exists

Regards

orchardbot commented 9 years ago

@jtkech commented:

Even I never use a Theme base on another one, I just tried it again For infos, I can repro each time on a 1.8.1 version, but I can't repro on a 1.8.x version Maybe because of the new Sessions / Transactions implementation (e.g in SessionLocator.cs)

Regards

orchardbot commented 9 years ago

PaulDevenney commented:

this is almost certainly the same issue as https://orchard.codeplex.com/workitem/21176.