예제 #1
0
        public bool DropIndex(string memberPath)
        {
            IndexWrapper index;

            if (IndexCache.TryGetValue(memberPath, out index))
            {
                IndexCache.Remove(memberPath);
                Remove(memberPath, _ => true);
                index.Drop();
                return(true);
            }
            return(false);
        }
예제 #2
0
        /// <summary>
        /// Returns the indexed children for this user from the cache. Caches them if not already there.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="indexBy">The index by.</param>
        /// <returns>IEnumerable{BaseItem}.</returns>
        private IEnumerable <BaseItem> GetIndexedChildren(User user, string indexBy)
        {
            List <BaseItem> result;
            var             cacheKey = user.Name + indexBy;

            IndexCache.TryGetValue(cacheKey, out result);

            if (result == null)
            {
                //not cached - cache it
                Func <User, IEnumerable <BaseItem> > indexing;
                IndexByOptions.TryGetValue(indexBy, out indexing);
                result = BuildIndex(indexBy, indexing, user);
            }
            return(result);
        }
예제 #3
0
        public bool EnsureIndex(IndexDefinition indexDefinition)
        {
            // Try to not rebuild index, so we check if there exists an equal defintion already
            IndexWrapper existing;

            if (IndexCache.TryGetValue(indexDefinition.Path, out existing))
            {
                if (indexDefinition.Options.Equals(existing.IndexDefinition.Options))
                {
                    // phew, existing index was already matching. bail out
                    return(false);
                }
                DropIndex(indexDefinition.Path);
            }

            // An index can not both exclude certain values and at the same time include certain values
            var hasIncludeValues = (indexDefinition.Options.IncludeValues != null) &&
                                   (indexDefinition.Options.IncludeValues.Length > 0);
            var hasExcludeValues = (indexDefinition.Options.ExcludeValues != null) &&
                                   (indexDefinition.Options.ExcludeValues.Length > 0);

            if (hasIncludeValues && hasExcludeValues)
            {
                throw new KiwiDbException("An index can not have an exclusion list and an inclusion list at the same time.");
            }

            var index = new IndexWrapper(this, indexDefinition)
            {
                IsChanged = true
            };

            IndexCache.Add(indexDefinition.Path, index);
            Insert(indexDefinition.Path, JSON.FromObject(indexDefinition));

            // rebuild index
            foreach (var record in MasterTable.Scan())
            {
                UpdateIndex(record.Key, null, record.Value);
            }
            return(true);
        }
예제 #4
0
        public IIndex GetIndex(string memberPath)
        {
            IndexWrapper indexWrapper;

            return(IndexCache.TryGetValue(memberPath, out indexWrapper) ? indexWrapper : null);
        }