public void Retrieving_All_Content_In_Site() { //NOTE: Doing this the old 1 by 1 way and based on the results of the ContentServicePerformanceTest.Retrieving_All_Content_In_Site // the old way takes 143795ms, the new above way takes: // 14249ms // // ... NOPE, made some new changes, it is now.... // 5290ms !!!!!! // // that is a 96% savings of processing and sql calls! // // ... NOPE, made even more nice changes, it is now... // 4452ms !!!!!!! var contentType1 = MockedContentTypes.CreateTextpageContentType("test1", "test1"); var contentType2 = MockedContentTypes.CreateTextpageContentType("test2", "test2"); var contentType3 = MockedContentTypes.CreateTextpageContentType("test3", "test3"); ServiceContext.ContentTypeService.Save(new[] { contentType1, contentType2, contentType3 }); contentType1.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy <int>(() => contentType2.Id), 0, contentType2.Alias), new ContentTypeSort(new Lazy <int>(() => contentType3.Id), 1, contentType3.Alias) }; contentType2.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy <int>(() => contentType1.Id), 0, contentType1.Alias), new ContentTypeSort(new Lazy <int>(() => contentType3.Id), 1, contentType3.Alias) }; contentType3.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy <int>(() => contentType1.Id), 0, contentType1.Alias), new ContentTypeSort(new Lazy <int>(() => contentType2.Id), 1, contentType2.Alias) }; ServiceContext.ContentTypeService.Save(new[] { contentType1, contentType2, contentType3 }); var roots = MockedContent.CreateTextpageContent(contentType1, -1, 10); ServiceContext.ContentService.Save(roots); foreach (var root in roots) { var item1 = MockedContent.CreateTextpageContent(contentType1, root.Id, 10); var item2 = MockedContent.CreateTextpageContent(contentType2, root.Id, 10); var item3 = MockedContent.CreateTextpageContent(contentType3, root.Id, 10); ServiceContext.ContentService.Save(item1.Concat(item2).Concat(item3)); } var total = new List <IContent>(); using (DisposableTimer.TraceDuration <ContentServicePerformanceTest>("Getting all content in site")) { TestProfiler.Enable(); total.AddRange(ServiceContext.ContentService.GetRootContent()); foreach (var content in total.ToArray()) { total.AddRange(ServiceContext.ContentService.GetDescendants(content)); } TestProfiler.Disable(); LogHelper.Info <ContentServicePerformanceTest>("Returned " + total.Count + " items"); } }
public void Retrieving_All_Content_In_Site() { // NOTE: Doing this the old 1 by 1 way and based on the results of the ContentServicePerformanceTest.Retrieving_All_Content_In_Site // the old way takes 143795ms, the new above way takes: // 14249ms // // ... NOPE, made some new changes, it is now.... // 5290ms !!!!!! // // that is a 96% savings of processing and sql calls! // // ... NOPE, made even more nice changes, it is now... // 4452ms !!!!!!! Template template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); ContentType contentType1 = ContentTypeBuilder.CreateTextPageContentType("test1", "test1", defaultTemplateId: template.Id); ContentType contentType2 = ContentTypeBuilder.CreateTextPageContentType("test2", "test2", defaultTemplateId: template.Id); ContentType contentType3 = ContentTypeBuilder.CreateTextPageContentType("test3", "test3", defaultTemplateId: template.Id); ContentTypeService.Save(new[] { contentType1, contentType2, contentType3 }); contentType1.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy <int>(() => contentType2.Id), 0, contentType2.Alias), new ContentTypeSort(new Lazy <int>(() => contentType3.Id), 1, contentType3.Alias) }; contentType2.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy <int>(() => contentType1.Id), 0, contentType1.Alias), new ContentTypeSort(new Lazy <int>(() => contentType3.Id), 1, contentType3.Alias) }; contentType3.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy <int>(() => contentType1.Id), 0, contentType1.Alias), new ContentTypeSort(new Lazy <int>(() => contentType2.Id), 1, contentType2.Alias) }; ContentTypeService.Save(new[] { contentType1, contentType2, contentType3 }); IEnumerable <Content> roots = ContentBuilder.CreateTextpageContent(contentType1, -1, 10); ContentService.Save(roots); foreach (Content root in roots) { IEnumerable <Content> item1 = ContentBuilder.CreateTextpageContent(contentType1, root.Id, 10); IEnumerable <Content> item2 = ContentBuilder.CreateTextpageContent(contentType2, root.Id, 10); IEnumerable <Content> item3 = ContentBuilder.CreateTextpageContent(contentType3, root.Id, 10); ContentService.Save(item1.Concat(item2).Concat(item3)); } var total = new List <IContent>(); using (GetTestProfilingLogger().TraceDuration <ContentServicePerformanceTest>("Getting all content in site")) { TestProfiler.Enable(); total.AddRange(ContentService.GetRootContent()); foreach (IContent content in total.ToArray()) { total.AddRange(ContentService.GetPagedDescendants(content.Id, 0, int.MaxValue, out long _)); } TestProfiler.Disable(); StaticApplicationLogging.Logger.LogInformation("Returned {Total} items", total.Count); } }