1

Resolved

Random sorting does not work if syscache module is enabled

description

When designing a query and choosing "Sort randomly", the query will not sort randomly when you enable the syscache module.

This happens because the query will be cached in the NHibernate-provider. However, the sorting is done on the database server.

I changed the following in DefaultHqlQuery:
        public IEnumerable<ContentItem> Slice(int skip, int count) {
            ApplyHqlVersionOptionsRestrictions(_versionOptions);
            var hql = ToHql(false);

            /* START FIX HERE */
            bool cacheIt = true;
            foreach (var sort in _sortings)
            {
                var sortFactory = new DefaultHqlSortFactory();
                sort.Item2(sortFactory);

                if (sortFactory.Randomize)
                {
                    cacheIt = false;
                    break;
                }
            }
            /* END FIX HERE */

            var query = _session
                .CreateQuery(hql)
                .SetCacheable(cacheIt)
                ;

            if (skip != 0) {
                query.SetFirstResult(skip);
            }
            if (count != 0 && count != Int32.MaxValue) {
                query.SetMaxResults(count);
            }

            var ids = query
                .SetResultTransformer(Transformers.AliasToEntityMap)
                .List<IDictionary>()
                .Select(x => (int)x["Id"]);

            return ContentManager.GetManyByVersionId(ids, QueryHints.Empty);
        }

comments

sebastienros wrote Jul 8, 2013 at 3:28 AM

Fixed in changeset 34728efdb61e

hkui wrote Jul 8, 2013 at 8:01 AM

I think you made a small mistake, sebastienros:
                    bool cacheable = true;
                    if (!sortFactory.Randomize) {
                             cacheable = false;
I think it should set cacheable = false; when sortFactory.Randomize equals true.

sebastienros wrote Jul 8, 2013 at 5:58 PM

:/

thanks

sfmskywalker wrote Mar 28 at 1:28 AM

Fixed in changeset 24f66bb022ae61677338cef5fc2376e625c42f99

hkui wrote Mar 28 at 7:09 AM

sfmskywalker: Where can i view that changeset?