public void Getting_1000_Cached_Items() { // Arrange IContentType contentType = ContentTypeService.Get(ContentType.Id); IEnumerable <Content> pages = ContentBuilder.CreateTextpageContent(contentType, -1, 1000); ContentService.Save(pages, 0); using (IScope scope = ScopeProvider.CreateScope()) { DocumentRepository repository = DocumentRepository; // Act IEnumerable <IContent> contents = repository.GetMany(); var watch = Stopwatch.StartNew(); IEnumerable <IContent> contentsCached = repository.GetMany(); watch.Stop(); long elapsed = watch.ElapsedMilliseconds; Debug.Print("1000 content items retrieved in {0} ms with caching", elapsed); // Assert // Assert.That(contentsCached.Any(x => x.HasIdentity == false), Is.False); // Assert.That(contentsCached.Any(x => x == null), Is.False); // Assert.That(contentsCached.Count(), Is.EqualTo(contents.Count())); } }
public void Getting_1000_Uncached_Items() { // Arrange var contentType = ContentTypeService.Get(ContentType.Id); var pages = ContentBuilder.CreateTextpageContent(contentType, -1, 1000); ContentService.Save(pages, 0); using (var scope = ScopeProvider.CreateScope()) { var repository = DocumentRepository; // Act var watch = Stopwatch.StartNew(); var contents = repository.GetMany(); watch.Stop(); var elapsed = watch.ElapsedMilliseconds; Debug.Print("1000 content items retrieved in {0} ms without caching", elapsed); // Assert // Assert.That(contents.Any(x => x.HasIdentity == false), Is.False); // Assert.That(contents.Any(x => x == null), Is.False); } }
public void Creating_1000_Items() { // Arrange IContentType contentType = ContentTypeService.Get(ContentType.Id); IEnumerable <Content> pages = ContentBuilder.CreateTextpageContent(contentType, -1, 1000); // Act var watch = Stopwatch.StartNew(); ContentService.Save(pages, 0); watch.Stop(); long elapsed = watch.ElapsedMilliseconds; Debug.Print("100 content items saved in {0} ms", elapsed); // Assert Assert.That(pages.Any(x => x.HasIdentity == false), Is.False); }
/// <summary> /// Returns the available composite content types for a given content type /// </summary> /// <param name="type"></param> /// <param name="filterContentTypes"> /// This is normally an empty list but if additional content type aliases are passed in, any content types containing /// those aliases will be filtered out /// along with any content types that have matching property types that are included in the filtered content types /// </param> /// <param name="filterPropertyTypes"> /// This is normally an empty list but if additional property type aliases are passed in, any content types that have /// these aliases will be filtered out. /// This is required because in the case of creating/modifying a content type because new property types being added to /// it are not yet persisted so cannot /// be looked up via the db, they need to be passed in. /// </param> /// <param name="contentTypeId"></param> /// <param name="isElement">Whether the composite content types should be applicable for an element type</param> /// <returns></returns> protected ActionResult <IEnumerable <Tuple <EntityBasic?, bool> > > PerformGetAvailableCompositeContentTypes( int contentTypeId, UmbracoObjectTypes type, string[]?filterContentTypes, string[]?filterPropertyTypes, bool isElement) { IContentTypeComposition?source = null; //below is all ported from the old doc type editor and comes with the same weaknesses /insanity / magic IContentTypeComposition[] allContentTypes; switch (type) { case UmbracoObjectTypes.DocumentType: if (contentTypeId > 0) { source = ContentTypeService.Get(contentTypeId); if (source == null) { return(NotFound()); } } allContentTypes = ContentTypeService.GetAll().Cast <IContentTypeComposition>().ToArray(); break; case UmbracoObjectTypes.MediaType: if (contentTypeId > 0) { source = MediaTypeService.Get(contentTypeId); if (source == null) { return(NotFound()); } } allContentTypes = MediaTypeService.GetAll().Cast <IContentTypeComposition>().ToArray(); break; case UmbracoObjectTypes.MemberType: if (contentTypeId > 0) { source = MemberTypeService.Get(contentTypeId); if (source == null) { return(NotFound()); } } allContentTypes = MemberTypeService.GetAll().Cast <IContentTypeComposition>().ToArray(); break; default: throw new ArgumentOutOfRangeException("The entity type was not a content type"); } ContentTypeAvailableCompositionsResults availableCompositions = ContentTypeService.GetAvailableCompositeContentTypes(source, allContentTypes, filterContentTypes, filterPropertyTypes, isElement); IContentTypeComposition[] currCompositions = source == null ? new IContentTypeComposition[] { } : source.ContentTypeComposition.ToArray(); var compAliases = currCompositions.Select(x => x.Alias).ToArray(); IEnumerable <string> ancestors = availableCompositions.Ancestors.Select(x => x.Alias); return(availableCompositions.Results .Select(x => new Tuple <EntityBasic?, bool>(UmbracoMapper.Map <IContentTypeComposition, EntityBasic>(x.Composition), x.Allowed)) .Select(x => { //we need to ensure that the item is enabled if it is already selected // but do not allow it if it is any of the ancestors if (compAliases.Contains(x.Item1?.Alias) && ancestors.Contains(x.Item1?.Alias) == false) { //re-set x to be allowed (NOTE: I didn't know you could set an enumerable item in a lambda!) x = new Tuple <EntityBasic?, bool>(x.Item1, true); } //translate the name if (x.Item1 is not null) { x.Item1.Name = TranslateItem(x.Item1.Name); } IContentTypeComposition?contentType = allContentTypes.FirstOrDefault(c => c.Key == x.Item1?.Key); EntityContainer[] containers = GetEntityContainers(contentType, type).ToArray(); var containerPath = $"/{(containers.Any() ? $"{string.Join("/", containers.Select(c => c.Name))}/" : null)}"; if (x.Item1 is not null) { x.Item1.AdditionalData["containerPath"] = containerPath; } return x; }) .ToList()); }
/// <summary> /// Returns a list of content types where a particular composition content type is used /// </summary> /// <param name="type">Type of content Type, eg documentType or mediaType</param> /// <param name="contentTypeId">Id of composition content type</param> /// <returns></returns> protected ActionResult <IEnumerable <EntityBasic> > PerformGetWhereCompositionIsUsedInContentTypes( int contentTypeId, UmbracoObjectTypes type) { var id = 0; if (contentTypeId > 0) { IContentTypeComposition?source; switch (type) { case UmbracoObjectTypes.DocumentType: source = ContentTypeService.Get(contentTypeId); break; case UmbracoObjectTypes.MediaType: source = MediaTypeService.Get(contentTypeId); break; case UmbracoObjectTypes.MemberType: source = MemberTypeService.Get(contentTypeId); break; default: throw new ArgumentOutOfRangeException(nameof(type)); } if (source == null) { return(NotFound()); } id = source.Id; } IEnumerable <IContentTypeComposition> composedOf; switch (type) { case UmbracoObjectTypes.DocumentType: composedOf = ContentTypeService.GetComposedOf(id); break; case UmbracoObjectTypes.MediaType: composedOf = MediaTypeService.GetComposedOf(id); break; case UmbracoObjectTypes.MemberType: composedOf = MemberTypeService.GetComposedOf(id); break; default: throw new ArgumentOutOfRangeException(nameof(type)); } EntityBasic TranslateName(EntityBasic e) { e.Name = TranslateItem(e.Name); return(e); } return(composedOf .Select(UmbracoMapper.Map <IContentTypeComposition, EntityBasic>) .WhereNotNull() .Select(TranslateName) .ToList()); }