Skip to content

Commit

Permalink
perf: optimize terms supports type
Browse files Browse the repository at this point in the history
  • Loading branch information
AElfBourneShi committed Oct 19, 2024
1 parent f2c063d commit 402b22d
Showing 1 changed file with 10 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,41 +327,22 @@ private void HandleNestedContains(SubQueryExpression subQueryExpression, Express
QueryMap[expression].SubQueryFullPath = subQueryFullPath;
}

private static readonly HashSet<Type> SupportedTermsTypes = new HashSet<Type>
{
typeof(Guid), typeof(Guid?),
typeof(int), typeof(int?),
typeof(long), typeof(long?),
typeof(double), typeof(double?),
typeof(bool), typeof(bool?)
};

private Node GetDifferentTypesTermsQueryNode()
{
Node query;
if (PropertyType == typeof(Guid))
if (SupportedTermsTypes.Contains(PropertyType))
{
query = new TermsNode(PropertyName, ((IEnumerable<Guid>)Value).Select(x => x.ToString()));
}
else if (PropertyType == typeof(Guid?))
{
query = new TermsNode(PropertyName, ((IEnumerable<Guid?>)Value).Select(x => x.ToString()));
}
else if (PropertyType == typeof(int))
{
query = new TermsNode(PropertyName, ((IEnumerable<int>)Value).Select(x => x.ToString()));
}
else if (PropertyType == typeof(int?))
{
query = new TermsNode(PropertyName, ((IEnumerable<int?>)Value).Select(x => x.ToString()));
}
else if (PropertyType == typeof(long))
{
query = new TermsNode(PropertyName, ((IEnumerable<long>)Value).Select(x => x.ToString()));
}
else if (PropertyType == typeof(long?))
{
query = new TermsNode(PropertyName, ((IEnumerable<long?>)Value).Select(x => x.ToString()));
}
else if (PropertyType == typeof(double))
{
query = new TermsNode(PropertyName, ((IEnumerable<double>)Value).Select(x => x.ToString()));
}
else if(PropertyType == typeof(double?))
{
query = new TermsNode(PropertyName, ((IEnumerable<double?>)Value).Select(x => x.ToString()));
}
else if (PropertyType == typeof(DateTime))
{
query = new TermsNode(PropertyName,
Expand All @@ -372,14 +353,6 @@ private Node GetDifferentTypesTermsQueryNode()
query = new TermsNode(PropertyName,
((IEnumerable<DateTime?>)Value).Select(x => x.ToString()));
}
else if (PropertyType == typeof(bool))
{
query = new TermsNode(PropertyName, ((IEnumerable<bool>)Value).Select(x => x.ToString()));
}
else if (PropertyType == typeof(bool?))
{
query = new TermsNode(PropertyName, ((IEnumerable<bool?>)Value).Select(x => x.ToString()));
}
else if (PropertyType == typeof(string))
{
query = new TermsNode(PropertyName, (IEnumerable<string>)Value);
Expand Down

0 comments on commit 402b22d

Please sign in to comment.