Beispiel #1
0
        private QueryHolder CreateQueries(XmlSitemapBuildContext ctx)
        {
            var storeId = ctx.Store.Id;

            if (_services.StoreService.IsSingleStoreMode())
            {
                storeId = 0;
            }

            // Always work with store-dependant setting
            var seoSettings = _services.Settings.LoadSetting <SeoSettings>(storeId);

            var holder = new QueryHolder();

            if (seoSettings.XmlSitemapIncludesCategories)
            {
                holder.Categories = _categoryService.BuildCategoriesQuery(showHidden: false, storeId: storeId);
            }

            if (seoSettings.XmlSitemapIncludesManufacturers)
            {
                holder.Manufacturers = _manufacturerService.GetManufacturers(false).OrderBy(x => x.DisplayOrder).ThenBy(x => x.Name);
            }

            if (seoSettings.XmlSitemapIncludesTopics)
            {
                holder.Topics = _topicService.GetAllTopics(storeId).AlterQuery(q =>
                {
                    return(q.Where(t => t.IncludeInSitemap && !t.RenderAsWidget));
                }).SourceQuery;
            }

            if (seoSettings.XmlSitemapIncludesProducts)
            {
                var searchQuery = new CatalogSearchQuery()
                                  .VisibleOnly()
                                  .VisibleIndividuallyOnly(true)
                                  .HasStoreId(storeId);

                holder.Products = _catalogSearchService.PrepareQuery(searchQuery);
            }

            return(holder);
        }
Beispiel #2
0
        private async Task <IEnumerable <NamedEntity> > EnumerateEntitiesAsync(QueryHolder queries)
        {
            if (queries.Categories != null)
            {
                var categories = await queries.Categories.Select(x => new { x.Id, x.UpdatedOnUtc }).ToListAsync();

                return(categories.Select(x => new NamedEntity {
                    EntityName = "Category", Id = x.Id, LastMod = x.UpdatedOnUtc
                }));
            }

            if (queries.Manufacturers != null)
            {
                var manufacturers = await queries.Manufacturers.Select(x => new { x.Id, x.UpdatedOnUtc }).ToListAsync();

                return(manufacturers.Select(x => new NamedEntity {
                    EntityName = "Manufacturer", Id = x.Id, LastMod = x.UpdatedOnUtc
                }));
            }

            if (queries.Topics != null)
            {
                var topics = await queries.Topics.Select(x => new { x.Id }).ToListAsync();

                return(topics.Select(x => new NamedEntity {
                    EntityName = "Topic", Id = x.Id, LastMod = DateTime.UtcNow
                }));
            }

            if (queries.Products != null)
            {
                var query = queries.Products.AsNoTracking();
                var maxId = int.MaxValue;

                //var limit = 0;
                while (maxId > 1)
                {
                    var products = await query
                                   .Where(x => x.Id < maxId)
                                   .OrderByDescending(x => x.Id)
                                   .Take(() => MaximumSiteMapNodeCount)
                                   .Select(x => new { x.Id, x.UpdatedOnUtc })
                                   .ToListAsync();

                    //limit++;
                    //if (limit >= 100)
                    //{
                    //	break;
                    //}

                    if (products.Count == 0)
                    {
                        break;
                    }

                    maxId = products.Last().Id;

                    return(products.Select(x => new NamedEntity {
                        EntityName = "Product", Id = x.Id, LastMod = x.UpdatedOnUtc
                    }));
                }
            }

            return(Enumerable.Empty <NamedEntity>());
        }