U4-6003 List View - Order By Custom Property Fix

Original work done on https://github.com/umbraco/Umbraco-CMS/pull/711 but ported to the latest version

Content below for reference
With the current implementation of the list view you can only sort by system columns (Name, SortOrder etc.) and not custom columns you have added to your document types. This PR allows that.

The crux of it is a sub-query added to the ORDER BY clause when we are ordering by a custom field. This looks up the field's value from the most recent content version.

Provided here and not in the previous pull request is:

MySQL support
Have done some performance testing. On a local laptop with 1000 nodes in a list view, it's sorting in around 220-250ms. It's a little slower that sorting on native properties like node name, but still perfectly usable - there's no significant delay you see in use.
Please note also:

GetPagedResultsByQuery() in VersionableRepositoryBase was previously doing an ORDER BY in SQL and then repeating this via LINQ to Objects. I couldn't see that this second ordering was necessary so removed it, but wanted to flag here in case I've missed something around why this was necessary.
The PR also includes small amends to fix or hide sorting on a couple of the default columns for the member amd media list views.
This commit is contained in:
André Ferreira
2016-02-26 14:30:32 +00:00
parent ac2ebc4071
commit bd2a40d214
31 changed files with 2526 additions and 2457 deletions

View File

@@ -322,7 +322,7 @@ namespace Umbraco.Core.Persistence.SqlSyntax
GetQuotedColumnName(foreignKey.ForeignColumns.First()),
GetQuotedTableName(foreignKey.PrimaryTable),
GetQuotedColumnName(foreignKey.PrimaryColumns.First()),
FormatCascade("DELETE", foreignKey.OnDelete),
FormatCascade("DELETE", foreignKey.OnDelete),
FormatCascade("UPDATE", foreignKey.OnUpdate));
}
@@ -331,7 +331,7 @@ namespace Umbraco.Core.Persistence.SqlSyntax
var sb = new StringBuilder();
foreach (var column in columns)
{
sb.Append(Format(column) +",\n");
sb.Append(Format(column) + ",\n");
}
return sb.ToString().TrimEnd(",\n");
}
@@ -431,11 +431,11 @@ namespace Umbraco.Core.Persistence.SqlSyntax
return GetSpecialDbType(column.DbType);
}
Type type = column.Type.HasValue
Type type = column.Type.HasValue
? DbTypeMap.ColumnDbTypeMap.First(x => x.Value == column.Type.Value).Key
: column.PropertyType;
if (type == typeof (string))
if (type == typeof(string))
{
var valueOrDefault = column.Size != default(int) ? column.Size : DefaultStringLength;
return string.Format(StringLengthColumnDefinitionFormat, valueOrDefault);
@@ -536,5 +536,9 @@ namespace Umbraco.Core.Persistence.SqlSyntax
public virtual string CreateConstraint { get { return "ALTER TABLE {0} ADD CONSTRAINT {1} {2} ({3})"; } }
public virtual string DeleteConstraint { get { return "ALTER TABLE {0} DROP CONSTRAINT {1}"; } }
public virtual string CreateForeignKeyConstraint { get { return "ALTER TABLE {0} ADD CONSTRAINT {1} FOREIGN KEY ({2}) REFERENCES {3} ({4}){5}{6}"; } }
public virtual string IsNull { get { return "ISNULL({0},{1})"; } }
public virtual string ConvertIntegerToOrderableString { get { return "RIGHT('00000000' + CAST({0} AS varchar(8)),8)"; } }
public virtual string ConvertDateToOrderableString { get { return "CONVERT(varchar, {0}, 102)"; } }
}
}