Knipex Assembly Pack (SB Board/Blister) 00 20 11
Reduced to kr591.20
Kistenberg Battery Box KBB03-115 Spaces For Batteries
Reduced to kr91.17
C#, SQL, Episerver/Optimizely, performance, and beyond
Knipex Assembly Pack (SB Board/Blister) 00 20 11
Reduced to kr591.20
Kistenberg Battery Box KBB03-115 Spaces For Batteries
Reduced to kr91.17
Today I stumped upon this question Solution for Handling File Upload Permissions in Episerver CMS 12, and there is a simple solution for that
Using the EditSecurity.aspx comes in handy but it is not very future proof as it is now removed in CMS 12 with its siblings WebForms part. However, we can easily make up for that by using the APIs – which is meant to remain for a long time. Even better, this could be set up to be done automatedly and repeatedly. The little secret is IContentSecurityRepository
which is what EditSecurity.aspx used under the hood.
To set the access right of a content, this is what you need
var contentlink = new ContentReference(100);
var content = _contentRepository.Get<IContent>(contentlink);
if (content is IContentSecurable securable)
{
var descriptor = securable.GetContentSecurityDescriptor();
//You might need to add this if your content is not Catalog
descriptor = (ContentAccessControlList)descriptor.CreateWriteableClone();
descriptor.Clear();
descriptor.AddEntry(new AccessControlEntry("Everyone", AccessLevel.Read, SecurityEntityType.Role));
descriptor.AddEntry(new AccessControlEntry("Author", AccessLevel.Read | AccessLevel.Create | AccessLevel.Edit | AccessLevel.Delete | AccessLevel.Publish, SecurityEntityType.Role));
//any other access rights that you need to set
_contentSecurityRepository.Save(contentlink, descriptor, SecuritySaveType.Replace);
}
The first two lines are from for demonstration, and not very “automated”. You might have some hard coded value there or might have to work your magic to find the right content. (Just a kind note, if you want your code to work consistently between sites, make sure to use ContentGuid
instead ContentId which is changed depending on the database).
The rest of the code is quite self-explanatory. You check if your content implements IContentSecurable
which is required to have access rights. Then you clear any existing access rights and add your desirable ones. Finally save it with the SecuritySaveType.Replace
to make sure that only access rights you wanted, exist.
This code can be run multiple times (Idempotent). You can add it to a scheduled job, or even better, a startup routine, to make sure that you always have the right access rights of specific content.
This happened a quite ago but only now I have had time to write about it.
Once upon a time, I was asked to look into a customer database (in a big engagement of helping them improving performance overall)
One thing stand out is this query
WITH CTE AS
(SELECT * FROM dbo.OrderGroupNote
WHERE OrderGroupId = @OrderGroupId)
MERGE CTE AS T
USING @OrderGroupNotes AS S
ON T.OrderNoteId = S.OrderNoteId
WHEN NOT MATCHED BY TARGET
THEN INSERT (
[OrderGroupId],
[CustomerId],
[Title],
[Type],
[Detail],
[Created],
[LineItemId],
[Channel],
[EventType])
VALUES(S.OrderGroupId,
S.CustomerId,
S.Title,
S.Type,
S.Detail,
S.Created,
S.LineItemId,
S.Channel,
S.EventType)
WHEN NOT MATCHED BY SOURCE
THEN DELETE
WHEN MATCHED AND (S.IsModified = 1) THEN
UPDATE SET
[OrderGroupId] = S.OrderGroupId,
[CustomerId] = S.CustomerId,
[Title] = S.Title,
[Type] = S.Type,
[Detail] = S.Detail,
[Created] = S.Created,
[LineItemId] = S.LineItemId,
[Channel] = S.Channel,
[EventType] = S.EventType;
If you can guess, that is the query to save the notes of an order. Normally it’s … fine. But for this customer, it is not, each save could result in almost 10GB, yes, you read it right, ten gigabytes of logical reads. Insane
The reason was, this customer has some orders with an absurd number of notes attached to it. The most one has 52k notes. And there are, in total, 94 orders with more than 1000 notes.
Upon investigation, they have a job to validate payment of invalid orders, which runs every 10 minutes. If the validation failed, a note will be added to the order. But because of no “limit” or “cut off”, that’s kept going for forever and continuing to add notes to orders. Each time, the operation becomes more expensive.
As a side note, this is note only expensive on the saving (to the database). It’s expensive to load from database, and it’s expensive to create all the objects in the memory.
The fix in this case is obviously to trim old notes, and to make sure that if the validation failed for X times, stop processing further.
But you might ask, could we do better. could we not save the entire order notes collection just because one note is added? That’s a good question. A really good one. I took a shot at that, but it’s … complicated. This is where we are held back by our promises of keeping thing backward compatible. When we try to make it better – you can do it better yourself as well. Make sure you do not have orders with an unusually high amount of notes.
SELECT
ordergroupid,
COUNT(OrderNoteId) AS notecount
FROM
OrderGroupNote
GROUP BY
ordergroupid
ORDER BY
notecount DESC;
If the most you have is less than 10, all good, less than 20 is fine. More than that and you might want to check why those orders have that many notes.
LEGO Icons Bukett med vilda blommor, med Lavendel och Gerbera, Pyssel Projekt för Inredning
Reduced to kr436.80
LEGO Icons NASA Artemis Space Launch System
Reduced to kr2,301.99
Levi’s herr Jeans 501 Original Fit (multiple size/color)
Reduced to kr574.00
Power Strip with Switch,Multiple Socket with USB
Reduced to kr291.50
Under Armour mens heatgear armour leggings
Reduced to kr277.10
If you are using catalog system, the way of creating metafields are easy – in fact, you can forget about “metafields”, all you should be using is the typed content type. Adding this attribute to your property is enough to set the precision as you wish.
[DecimalSettings(10, 2)]
public virtual Decimal MyAttributesDecimal { get; set; }
Thing is a little different if you are using order system. You don’t have the strongly typed order types to work with. To automate the metafield creation, you will have to use the underlying MetaField API yourself. You probably know how to create a metafield and add it to a desirable metaclass
var metaField = MetaField.Create(MetaDataContext.Instance, "Mediachase.Commerce.Orders.System.Shipment", "NewMetaField3", "new", "temp",
MetaDataType.Decimal, 17, true, true, false, false);
var metaClass = MetaClass.Load(MetaDataContext.Instance, "ShipmentEx");
metaClass.AddField(metaField);
However, metafield created this way will be added to the metaclass with the default (18, 0) precision, which is kind of pointless. How to control the precision of the decimal metafields?
The little secret is with the MetaField.Attributes. There are two attributes that control the precision of decimal type: MdpPrecision, and MdpScale. You have to set those after the metafield is created, but before it’s added to the metaclass (the reason was simple: the underlying query to add the column to the table looks for those values to set the precision of the column). Your code should look like this
var metaField = MetaField.Create(MetaDataContext.Instance, "Mediachase.Commerce.Orders.System.Shipment", "NewMetaField5", "new", "temp",
MetaDataType.Decimal, 17, true, true, false, false);
metaField.Attributes["MdpPrecision"] = "38";
metaField.Attributes["MdpScale"] = "9";
var metaClass = MetaClass.Load(MetaDataContext.Instance, "ShipmentEx");
metaClass.AddField(metaField);
A small but important note to remember: both of the attributes must be set, even if you want to leave one to default value.
And Tada!
Anker MagGo Power Bank, Qi2 Certified 15W MagSafe Compatible Portable Charger, 10.000mAh Battery Pack
Reduced to kr799.00
Soundcore by Anker Q20i Hybrid Active Noise Cancelling Headphones Wireless Over-Ear
Reduced to kr399.00
Regina Chamomile Paper 3-Ply Toilet Paper | 56 Roll Packs
Reduced to kr250.63
Reduced to kr131
Fjällräven Greenland Winter Jacket, size S
Normally 3999kr, reduced to kr2,363.89
Samsung Galaxy Buds3 Pro
Reduced to kr1,727.08
Kenwood Titanium Chef Baker Silver KVC85.004SI, Kitchen Assistant Food Processor, Integrated Scale, 3 Hook and Beaters for Mixing Stainless Steel and Rubber Beater, Bowls of 5L and 3.5L, 1200W, Silver
Reduced to kr4,058.00
Fluke Fluke 117 Multimeter, 600 V, Black, Yellow
Reduced to kr3,097.00
https://amzn.to/3ZVMC40
8Bitdo Ultimate C Bluetooth Controller for Switch with 6-axis Motion Control and Rumble Vibration (Pink)
Reduced to kr249.00, and a further 15% if buy 10 qualifying items with Prime membership
https://amzn.to/3BRKi69
Anker Prime Charger, 200W 6-Port GaN Charging Station
Reduced to kr749.00
Philips Airfryer Combi 7000 Series XXL – 8.3L (2kg), 22-in-1 airfryer (HD9876/90)
Reduced to kr2,499.00
Anker 335 67W Charger
Reduced to kr299.00
LEGO 10311 Icons Orkidé
Reduced to 348kr
PlayStation VR2
Reduced to kr4,675.46
AUDIO TECHNICA AudioT AT2035 Condenser Microphone
Reduced to kr1,347.43
Fjällräven Women’s Expedition Parka No.1 W Jacket
Reduced to kr4,884.51
Philips Connected AC4236/10 Air Purifier
Reduced to kr2990
Levi’s herr Jeans 501 Original Fit
Reduced to kr699
LG 32GS60QC-B – Ultragear monitor, 32″ QHD, 2560 x 1440, VA panel, 16:9, HDMI, 1 ms, 180Hz, FreeSync
Reduced to kr2,458.00
Fjallraven Expedition Long Down Parka W Jacket for Women
Reduced to kr4,546.31
PC GAMING Aqua PC Gamer – NVIDIA RTX 4060 8G – Watercooling 240mm white – Aqua View XT Case – B760-WIFI – Corsair Vengeance SL 2X8GB DDR4 3600 WH – SSD 1TB PCI 4.0 – Windows 11 Pro
Reduced to kr8,635.64
Merrell Herr Moab 3 GTX vandringssko
Reduced to kr773.00
PlayStation VR2
Reduced to kr4,697.07