Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V15: Fix reload memory cache endpoint #17446

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.PublishedCache;

namespace Umbraco.Cms.Api.Management.Controllers.PublishedCache;

Expand All @@ -11,9 +10,9 @@ public class CollectPublishedCacheController : PublishedCacheControllerBase
{
[HttpPost("collect")]
[MapToApiVersion("1.0")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status501NotImplemented)]
public async Task<IActionResult> Collect(CancellationToken cancellationToken)
{
return Ok();
return StatusCode(StatusCodes.Status501NotImplemented);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.PublishedCache;

namespace Umbraco.Cms.Api.Management.Controllers.PublishedCache;

Expand All @@ -11,7 +10,9 @@ public class StatusPublishedCacheController : PublishedCacheControllerBase
{
[HttpGet("status")]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status501NotImplemented)]
public async Task<ActionResult<string>> Status(CancellationToken cancellationToken)
=> await Task.FromResult(Ok("Obsoleted"));
{
return StatusCode(StatusCodes.Status501NotImplemented);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Umbraco.Cms.Core.Events;

Check warning on line 1 in src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (release/15.0)

❌ New issue: Overall Code Complexity

This module has a mean cyclomatic complexity of 4.12 across 17 functions. The mean complexity threshold is 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Persistence.Repositories;
Expand Down Expand Up @@ -86,36 +86,40 @@
var idsRemoved = new HashSet<int>();
IAppPolicyCache isolatedCache = AppCaches.IsolatedCaches.GetOrCreate<IContent>();

foreach (JsonPayload payload in payloads.Where(x => x.Id != default))
foreach (JsonPayload payload in payloads)
{
// By INT Id
isolatedCache.Clear(RepositoryCacheKeys.GetKey<IContent, int>(payload.Id));

// By GUID Key
isolatedCache.Clear(RepositoryCacheKeys.GetKey<IContent, Guid?>(payload.Key));

if (payload.Id != default)
{
// By INT Id
isolatedCache.Clear(RepositoryCacheKeys.GetKey<IContent, int>(payload.Id));

// By GUID Key
isolatedCache.Clear(RepositoryCacheKeys.GetKey<IContent, Guid?>(payload.Key));
}

// remove those that are in the branch
if (payload.ChangeTypes.HasTypesAny(TreeChangeTypes.RefreshBranch | TreeChangeTypes.Remove))
{
var pathid = "," + payload.Id + ",";
isolatedCache.ClearOfType<IContent>((k, v) => v.Path?.Contains(pathid) ?? false);
}

// if the item is not a blueprint and is being completely removed, we need to refresh the domains cache if any domain was assigned to the content
if (payload.Blueprint is false && payload.ChangeTypes.HasTypesAny(TreeChangeTypes.Remove))
{
idsRemoved.Add(payload.Id);
}


HandleMemoryCache(payload);
HandleRouting(payload);

HandleNavigation(payload);
HandlePublishedAsync(payload, CancellationToken.None).GetAwaiter().GetResult();
_idKeyMap.ClearCache(payload.Id);
if (payload.Id != default)
{
_idKeyMap.ClearCache(payload.Id);
}

Check warning on line 122 in src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (release/15.0)

❌ Getting worse: Complex Method

Refresh increases in cyclomatic complexity from 10 to 12, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
if (payload.Key.HasValue)
{
_idKeyMap.ClearCache(payload.Key.Value);
Expand Down
Loading