Skip to content

Commit 1a218f1

Browse files
authored
Merge pull request #7286 from umbraco/cms/database-availability-checks
16.2 Updates: Added details of abstractions of database availability checks, JSON serialization encoder creation and UseStrictDomainMatching option
2 parents 1edd87d + 4cf9804 commit 1a218f1

File tree

5 files changed

+116
-7
lines changed

5 files changed

+116
-7
lines changed

16/umbraco-cms/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@
424424
* [Custom Swagger API](reference/custom-swagger-api.md)
425425
* [Umbraco Flavored Markdown](reference/umbraco-flavored-markdown.md)
426426
* [Content Type Filters](reference/content-type-filters.md)
427+
* [Database Availability Checks](reference/database-availability.md)
428+
* [JSON Serialization](reference/json-serialization.md)
427429

428430
## Tutorials
429431

16/umbraco-cms/reference/configuration/cache-settings.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,31 @@ The `ContentTypeKeys` setting specifies which Document Types should be seeded in
5656
}
5757
```
5858

59-
### DocumentBreadthFirstSeedCount
59+
### DocumentBreadthFirstSeedCount and MediaBreadthFirstSeedCount
6060

61-
The `DocumentBreadthFirstSeedCount` setting specifies how many documents should be seeded into the cache when doing a breadth-first traversal. The default value is 100.
61+
The `DocumentBreadthFirstSeedCount` setting specifies how many documents should be seeded into the cache when doing a breadth-first traversal. `MediaBreadthFirstSeedCount` provides the same for media. The default value for both is 100.
6262

6363
```json
6464
"Umbraco": {
6565
"CMS": {
6666
"Cache": {
67-
"DocumentBreadthFirstSeedCount": 500
67+
"DocumentBreadthFirstSeedCount": 500,
68+
"MediaBreadthFirstSeedCount": 500
6869
}
6970
}
7071
}
7172
```
7273

73-
## MediaBreadthFirstSeedCount
74+
## DocumentSeedBatchSize and MediaSeedBatchSize
7475

75-
The `MediaBreadthFirstSeedCount` setting specifies how many media items should be seeded into the cache when doing a breadth-first traversal. The default value is 100.
76+
When populating the cache on startup the content keys defined by the seeding strategy are processed in batches. The batch size for documents and media can be modified via the `DocumentSeedBatchSize` and `MediaSeedBatchSize` respectively. The default value for both is 100.
7677

7778
```json
7879
"Umbraco": {
7980
"CMS": {
8081
"Cache": {
81-
"MediaBreadthFirstSeedCount": 500
82+
"DocumentSeedBatchSize": 500,
83+
"MediaSeedBatchSize": 500
8284
}
8385
}
8486
}

16/umbraco-cms/reference/configuration/webroutingsettings.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ An example of a web routing config with default values, and a placeholder for th
2020
"DisableFindContentByIdPath": false,
2121
"DisableRedirectUrlTracking": false,
2222
"UrlProviderMode": "Auto",
23-
"UmbracoApplicationUrl": "http://www.mysite.com/"
23+
"UmbracoApplicationUrl": "http://www.mysite.com/",
24+
"UseStrictDomainMatching": false
2425
}
2526
}
2627
}
@@ -104,3 +105,14 @@ Defines the Umbraco application URL that the server should reach itself. By defa
104105
{% hint style="info" %}
105106
Previously before v9, it was required to specify **backofffice** path as this was customizable (`/umbraco` by default). However, from v9+ this is no longer possible, so it's sufficient to use the URL that contains the scheme (http/https) and complete hostname.
106107
{% endhint %}
108+
109+
## Strict domain matching
110+
111+
With multi-site setups multiple root nodes will be prepared with assigned domains. When routing a request, the content matched by path below the root node that matches the domain is returned.
112+
113+
A request may be received on an unrecognized domain that otherwise matches by path to a content item. By default Umbraco will route this item.
114+
115+
With `UseStrictDomainMatching` set to `true`, the request will only be routed if the domain as well as the path matches.
116+
117+
Why use this? It's possible to receive requests on domains that are configured on web server but aren't setup as domains in Umbraco. The Azure web app default domain is an example of this. By switching this option on, requests that come in on that domain will no longer be routed.
118+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
description: Describes the checks Umbraco will do on startup to determine the availability of the database, and how this behavior can be customized.
3+
---
4+
5+
# Database Availability Checks
6+
7+
When Umbraco boots it will check for a configured database and, if found, verify that a connection can be made.
8+
9+
The default behavior is to check five times with a one second delay between attempts. If, after that, a connection cannot be established, Umbraco will fail with a `BootFailedException`.
10+
11+
## Implementing Custom Behavior
12+
13+
For projects in development with the potential for misconfigured database settings, this is likely a reasonable approach to take.
14+
15+
In production, when you have stable configuration, you may prefer to override the behavior to better handle cases where your hosting infrastructure might restart.
16+
17+
We support this by abstracting the default behavior behind the `IDatabaseAvailabilityCheck` interface found in the `Umbraco.Cms.Infrastructure.Persistence` namespace.
18+
19+
You can implement your own version of this interface and register it via a composer. This is shown in the following, stub example:
20+
21+
```csharp
22+
using Umbraco.Cms.Core.Composing;
23+
using Umbraco.Cms.Infrastructure.Persistence;
24+
25+
public class MyDatabaseAvailabilityCheckComposer : IComposer
26+
{
27+
public void Compose(IUmbracoBuilder builder)
28+
{
29+
builder.Services.AddUnique<IDatabaseAvailabilityCheck, MyDatabaseAvailabilityCheck>();
30+
}
31+
}
32+
33+
internal class MyDatabaseAvailabilityCheck : IDatabaseAvailabilityCheck
34+
{
35+
public bool IsDatabaseAvailable(IUmbracoDatabaseFactory databaseFactory)
36+
{
37+
// Provide your custom logic to check database availability, wait as required, and return true once a connection is established.
38+
return true;
39+
}
40+
}
41+
42+
```
43+
44+
For reference and inspiration, the default implementation can be found [in the Umbraco CMS source code](https://github.com/umbraco/Umbraco-CMS/blob/main/src/Umbraco.Infrastructure/Persistence/DefaultDatabaseAvailabilityCheck.cs).
45+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
description: Describes how the JSON serialization within Umbraco can be customized.
3+
---
4+
5+
# JSON Serialization
6+
7+
Umbraco uses JSON as a format to serialize information to the database and for output. For example, the configuration of data types and the property values of complex editors are serialized to JSON for persistence.
8+
9+
The serializers within Umbraco uses a `JavascriptEncoder` which only considers basic latin characters as unnecessary to encode.
10+
11+
## Implementing Custom Behavior
12+
13+
For projects making use of non-Latin characters you may want to amend this behavior. By doing so you can reduce the space the serialized information takes up in the database.
14+
15+
We support this by abstracting the default behavior behind the `IJsonSerializerEncoderFactory` interface found in the `Umbraco.Cms.Core.Serialization` namespace.
16+
17+
You can implement your own version of this interface and register it via a composer. This is shown in the following example that marks Cyrillic characters as excluded for encoding:
18+
19+
```csharp
20+
using System.Text.Encodings.Web;
21+
using System.Text.Unicode;
22+
using Umbraco.Cms.Core.Composing;
23+
using Umbraco.Cms.Core.Serialization;
24+
using Umbraco.Cms.Infrastructure.Serialization;
25+
26+
namespace Umbraco.Cms.Web.UI.Custom.SystemTextConfigurationEditor;
27+
28+
public class SystemTextConfigurationEditorComposer : IComposer
29+
{
30+
public void Compose(IUmbracoBuilder builder)
31+
{
32+
builder.Services.AddUnique<IJsonSerializerEncoderFactory, MyConfigurationEditorJsonSerializerEncoderFactory>();
33+
}
34+
}
35+
36+
internal class MyConfigurationEditorJsonSerializerEncoderFactory : IJsonSerializerEncoderFactory
37+
{
38+
public JavaScriptEncoder CreateEncoder<TSerializer>()
39+
where TSerializer : IJsonSerializer
40+
{
41+
return JavaScriptEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.Cyrillic);
42+
}
43+
}
44+
```
45+
46+
For reference, the default implementation can be found [in the Umbraco CMS source code](https://github.com/umbraco/Umbraco-CMS/blob/main/src/Umbraco.Infrastructure/Serialization/DefaultJsonSerializerEncoderFactory.cs).
47+
48+

0 commit comments

Comments
 (0)