private EntryTypeAndTagCollection <SongType> ProcessUnifiedTypesAndTags(SongQueryParams queryParams) { EntryTypeAndTagCollection <SongType> typesAndTags = null; if (queryParams.UnifyEntryTypesAndTags) { typesAndTags = EntryTypeAndTagCollection <SongType> .Create(EntryType.Song, queryParams.SongTypes, queryParams.TagIds, _querySource); queryParams.TagIds = queryParams.TagIds.Except(typesAndTags.TagIds).ToArray(); queryParams.SongTypes = queryParams.SongTypes.Except(typesAndTags.SubTypes).ToArray(); } return(typesAndTags); }
private async Task <TagTopUsagesAndCount <TEntry> > GetTopUsagesAndCountAsync <TUsage, TEntry, TSort, TSubType>( IDatabaseContext <Tag> ctx, int tagId, EntryType entryType, Func <IQueryable <TEntry>, EntryTypeAndTagCollection <TSubType>, IQueryable <TEntry> > whereExpression, int maxCount = 12) where TEntry : class, IEntryBase, IEntryWithTags <TUsage> where TUsage : TagUsage where TSubType : struct, Enum { var typeAndTag = EntryTypeAndTagCollection <TSubType> .Create(entryType, tagId, ctx, allowAllTags : true); var q = ctx.Query <TEntry>() .WhereNotDeleted(); q = whereExpression(q, typeAndTag); IReadOnlyCollection <TEntry> topUsages; int usageCount; try { topUsages = await q .OrderByTagUsage <TEntry, TUsage>(tagId) .Take(maxCount) .VdbToListAsync(); usageCount = await q.VdbCountAsync(); } catch (Exception x) when(x is SqlException or GenericADOException) { s_log.Warn(x, "Unable to get tag usages"); topUsages = new TEntry[0]; usageCount = 0; } return(new TagTopUsagesAndCount <TEntry> { TopUsages = topUsages, TotalCount = usageCount }); }
public static IQueryable <Song> WhereHasTypeOrTag(this IQueryable <Song> query, EntryTypeAndTagCollection <SongType> entryTypeAndTagCollection) { if (entryTypeAndTagCollection == null || entryTypeAndTagCollection.IsEmpty) { return(query); } if (!entryTypeAndTagCollection.SubTypes.Any()) { return(query.Where(song => song.Tags.Usages.Any(u => entryTypeAndTagCollection.TagIds.Contains(u.Tag.Id)))); } return(query.Where(song => entryTypeAndTagCollection.SubTypes.Contains(song.SongType) || song.Tags.Usages.Any(u => entryTypeAndTagCollection.TagIds.Contains(u.Tag.Id)))); }