コード例 #1
0
        public override async Task <List <CommentView> > PreparedSearchAsync(CommentSearch search, Requester requester)
        {
            logger.LogTrace($"Comment GetAsync called by {requester}");

            await FixWatchLimits(watchSource, requester, search.ContentLimit);

            return(await converter.SimpleSearchAsync(search, q =>
                                                     services.permissions.PermissionWhere(q, requester, Keys.ReadAction)));
        }
コード例 #2
0
        public override async Task <List <CommentView> > PreparedSearchAsync(CommentSearch search, Requester requester)
        {
            logger.LogTrace($"Comment GetAsync called by {requester}");

            List <CommentView> result = null;

            //Write a regression test for comment deletion alerts
            if (search.Ids.Count > 0 && OnlyIdSearch(search, requester))
            {
                result = singlecache.GetValues(search.Ids);

                //NOTE: there is a period of time where the cache could be invalid by the time you get this data. I'm willing
                //to accept slightly out of date information... but does that mean some people will NEVER get the updates? no,
                //it just means for THIS request, they may have something slightly amiss.
                if (result.Select(x => x.id).OrderBy(x => x).SequenceEqual(search.Ids.Distinct().OrderBy(x => x)))
                {
                    //THIS IS A WIN! It means we have all the comments we were searching for! Now just remove the ones you're NOT ALLOWED to see
                    var allowedIds = await services.provider.GetListAsync(await contentSource.SearchIds(
                                                                              new ContentSearch()
                    {
                        Ids = result.Select(x => x.parentId).ToList()
                    },
                                                                              q => services.permissions.PermissionWhere(q, requester, Keys.ReadAction))
                                                                          );

                    //Remove any that don't show up in allowed ids
                    result.RemoveAll(x => !allowedIds.Contains(x.parentId));
                    logger.LogDebug($"* Using in-memory comments ({string.Join(",", result.Select(x => x.id))}) for ids {string.Join(",", search.Ids)}");

                    return(result);
                }
            }

            await OptimizedCommentSearch(search, requester, async (f) => result = await converter.SimpleSearchAsync(search, f));

            return(result);
        }