What does the "check in memory" mean in Orchard CMS?
Asked Answered
V

1

3

I tried to customize the queries executed by Orchard.ContentManagement.DefaultContentManager but the following peace of code *1 render my efforts useless:

class DefaultContentManager 
{
  ...

  public virtual ContentItem Get(int id, VersionOptions options, QueryHints hints) {
        ...
        // implemention of the query comes here
        ...
  *1 -> // no record means content item is not in db
        if (versionRecord == null) {
            // check in memory
            var record = _contentItemRepository.Get(id);
            if (record == null) {
                return null;
            }

            versionRecord = GetVersionRecord(options, record);

            if (versionRecord == null) {
                return null;
            }
        }

The query is executed correctly and it does not return any data (which was my goal) but afterwards a second attempt *1 is executed to still get the content item.

Why is this part of code there? What is its purpose? Also why does the comment state check in memory and then the repository (DB table) is queried.

Valdemar answered 15/6, 2016 at 16:45 Comment(2)
It's already been verified at this point that the item doesn't exist in the database, but it may have just been created from code during the same request. In that case, the nHibernate session has the item, but the database doesn't have it yet. The repository hits the session, not the db directly, so if it's there, it'll retrieve it, but that'll happen in memory. Makes sense?Padrone
@BertrandLeRoy Makes perfect sense, thank you. Please post your comment as an answer so i can accept it.Valdemar
P
4

It's already been verified at this point that the item doesn't exist in the database, but it may have just been created from code during the same request. In that case, the nHibernate session has the item, but the database doesn't have it yet. The repository hits the session, not the db directly, so if it's there, it'll retrieve it, but that'll happen in memory.

Padrone answered 19/6, 2016 at 7:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.