Skip to content

Commit aac65a7

Browse files
committed
only set localisation if it's different than inherited localisation. this is important for front end performance as it reduces the number of iterations when getting the variant for the requested path
1 parent ce29975 commit aac65a7

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

core/Controllers/ApiController.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -520,19 +520,6 @@ public JsonResult Localisation(string p_path)
520520
var model = apiHelper.PathLocalisation(p_path);
521521
return Json(model);
522522
}
523-
[Authorize(Roles = PuckRoles.Puck, AuthenticationSchemes = Mvc.AuthenticationScheme)]
524-
public JsonResult RootsLocalisations(string ids)
525-
{
526-
var guids = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Guid.Parse(x));
527-
var result = new List<dynamic>();
528-
foreach (var guid in guids)
529-
{
530-
var revision = repo.PublishedOrCurrentRevisions(guid).FirstOrDefault();
531-
var variant = apiHelper.PathLocalisation(revision.Path);
532-
result.Add(new { path = revision.Path.ToLower(), variant = variant });
533-
}
534-
return Json(result);
535-
}
536523
[Authorize(Roles = PuckRoles.Localisation, AuthenticationSchemes = Mvc.AuthenticationScheme)]
537524
[HttpPost]
538525
public JsonResult Localisation(string p_path, string variant)
@@ -541,7 +528,8 @@ public JsonResult Localisation(string p_path, string variant)
541528
bool success = false;
542529
try
543530
{
544-
apiHelper.SetLocalisation(p_path, variant);
531+
if (apiHelper.PathLocalisation(p_path) != variant)
532+
apiHelper.SetLocalisation(p_path, variant);
545533
success = true;
546534
}
547535
catch (Exception ex)
@@ -551,6 +539,19 @@ public JsonResult Localisation(string p_path, string variant)
551539
}
552540
return Json(new { message = message, success = success });
553541
}
542+
[Authorize(Roles = PuckRoles.Puck, AuthenticationSchemes = Mvc.AuthenticationScheme)]
543+
public JsonResult RootsLocalisations(string ids)
544+
{
545+
var guids = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Guid.Parse(x));
546+
var result = new List<dynamic>();
547+
foreach (var guid in guids)
548+
{
549+
var revision = repo.PublishedOrCurrentRevisions(guid).FirstOrDefault();
550+
var variant = apiHelper.PathLocalisation(revision.Path);
551+
result.Add(new { path = revision.Path.ToLower(), variant = variant });
552+
}
553+
return Json(result);
554+
}
554555
[Authorize(Roles = PuckRoles.ChangeType, AuthenticationSchemes = Mvc.AuthenticationScheme)]
555556
public ActionResult ChangeTypeDialog(Guid id)
556557
{

core/Controllers/BaseController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public string GetVariant(string searchPath)
158158
if (!PuckCache.PathToLocale.TryGetValue(searchPath, out variant))
159159
{
160160
foreach (var entry in PuckCache.PathToLocale)
161-
{
161+
{//PathToLocale dictionary ordered by depth descending (based on number of forward slashes in path) so it's safe to break after first match
162162
if ((searchPath+"/").StartsWith(entry.Key+"/"))
163163
{
164164
variant = entry.Value;

0 commit comments

Comments
 (0)