Hi all,
I have written a couple of Custom Archive Providers and have implemented sorting into them.
All works Ok, sorting is fast but on customer site one of the Archives sorts but extremely slowly. The other just hangs and ramps up the CPU on the Server
NB there are only items in the archive so it's not that I am trying to sort thousands of records
Here is the code that I have in the SetOrderBy function
public void SetOrderBy(params ArchiveOrderByInfo[] orderBy)
{
string sOrderBy = string.Empty;
if (orderBy != null && orderBy.Length > 0)
{
foreach (ArchiveOrderByInfo orderByInfo in orderBy)
{
if (sOrderBy.Length > 0)
{
sOrderBy += ",";
}
sOrderBy += orderByInfo.Name + " " + orderByInfo.Direction.ToString();
}
GetRows(sOrderBy);
}
}
And here is the code that I have that sorts the ArchiveRows in the GetRows function to a max of two columns eg, "Order By Name ASC, Number DESC"
var filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First());
if (!options.StartsWith("rowcount"))
{
_sOrderBy = options;
}
if (!string.IsNullOrEmpty(_sOrderBy))
{
string[] sSplit = _sOrderBy.Split(',');
List<ArchiveOrderByInfo> orderByInfos = new List<ArchiveOrderByInfo>();
foreach (string s in sSplit)
{
string[] sSplit2 = s.Split(' ');
ArchiveOrderByInfo orderByInfo = new ArchiveOrderByInfo(sSplit2[0], OrderBySortType.ASC);
if (sSplit2[1] == "DESC")
{
orderByInfo.Direction = OrderBySortType.DESC;
}
orderByInfos.Add(orderByInfo);
}
if (orderByInfos.Count > 1)
{
filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First()).OrderBy(z => z.ColumnData[orderByInfos[0].Name].RawValue).ToList();
if (orderByInfos[0].Direction == OrderBySortType.ASC && orderByInfos[1].Direction == OrderBySortType.ASC)
{
filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First()).OrderBy(z => z.ColumnData[orderByInfos[0].Name].RawValue).ThenBy(z => z.ColumnData[orderByInfos[1].Name].RawValue).ToList();
}
else if (orderByInfos[0].Direction == OrderBySortType.DESC && orderByInfos[1].Direction == OrderBySortType.ASC)
{
filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First()).OrderByDescending(z => z.ColumnData[orderByInfos[0].Name].RawValue).ThenBy(z => z.ColumnData[orderByInfos[1].Name].RawValue).ToList();
}
else if (orderByInfos[0].Direction == OrderBySortType.ASC && orderByInfos[1].Direction == OrderBySortType.DESC)
{
filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First()).OrderBy(z => z.ColumnData[orderByInfos[0].Name].RawValue).ThenByDescending(z => z.ColumnData[orderByInfos[1].Name].RawValue).ToList();
}
else
{
filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First()).OrderByDescending(z => z.ColumnData[orderByInfos[0].Name].RawValue).ThenByDescending(z => z.ColumnData[orderByInfos[1].Name].RawValue).ToList();
}
}
else
{
filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First()).OrderBy(z => z.ColumnData[orderByInfos[0].Name].RawValue).ToList();
if (orderByInfos[0].Direction == OrderBySortType.DESC)
{
filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First()).OrderByDescending(z => z.ColumnData[orderByInfos[0].Name].RawValue).ToList();
}
}
}
Like I say it all works fine on my Dev PC but not on the Customer Server so I don't think that it is anything particularly wrong with the code and it ending up in a loop when clicking a column header or doing it from the sort columns menu
Has anyone come across something similar before?
Cheers James