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

v8: ContentService.GetById gets cached version when using Key (Guid) #4407

Closed
KevinJump opened this issue Feb 4, 2019 · 3 comments
Closed
Labels

Comments

@KevinJump
Copy link
Contributor

Latest Nightly : 8.0.0-alpha.58.2084

Calling the ContentService to get a content item by Key (Guid) returns a cached version of the item, not the latest version.

If you call the contentService.GetById with the int id you get the latest version

Reproduction

I had the following code in an ApIController (Id / Guid is same bit of content for test)

var item = Services.ContentService.GetById(1061);
Logger.Info<uSyncDashboardApiController>($"By Id Content Version: {item.VersionId}");

var itemByKey = Services.ContentService.GetById(Guid.Parse("fdfa7dd1-b45d-4a14-bc66-83f441df2d69"));
Logger.Info<uSyncDashboardApiController>($"By Key Content Version: {itemByKey.VersionId}");
  1. Before content modification log :
By Id Content Version: 2
By Key Content Version: 2 

2 . Go to content update a field and publish the node
3. Call after publish (new version of content)

By Id Content Version: 3
By Key Content Version: 2 

You might not really notice this until you try and save the via the content service and you get Cannot save a non-current version because your version is old.

@kjac
Copy link
Contributor

kjac commented Feb 4, 2019

Duplicate of #2997

@Emetico
Copy link

Emetico commented Aug 5, 2019

Possible work around for v8, until it is fixed.

public IContent GetLatestVersion(int documentId)
{
    IContent document = contentService.GetById(documentId);
    int lastestVersionId = contentService.GetVersionIds(document.Id, 1).First();
    return lastestVersionId == document.VersionId ? document : contentService.GetVersion(lastestVersionId);
}

@nul800sebastiaan
Copy link
Member

I'll close this as a duplicate of #2997

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants