From 402b22dfd676541d00b6dedcd185ba7f22e66ff2 Mon Sep 17 00:00:00 2001 From: Bourne Shi Date: Sat, 19 Oct 2024 10:56:26 +0800 Subject: [PATCH] perf: optimize terms supports type --- .../Linq/GeneratorExpressionTreeVisitor.cs | 47 ++++--------------- 1 file changed, 10 insertions(+), 37 deletions(-) diff --git a/src/AElf.EntityMapping.Elasticsearch/Linq/GeneratorExpressionTreeVisitor.cs b/src/AElf.EntityMapping.Elasticsearch/Linq/GeneratorExpressionTreeVisitor.cs index 34bae13..37db570 100644 --- a/src/AElf.EntityMapping.Elasticsearch/Linq/GeneratorExpressionTreeVisitor.cs +++ b/src/AElf.EntityMapping.Elasticsearch/Linq/GeneratorExpressionTreeVisitor.cs @@ -327,41 +327,22 @@ private void HandleNestedContains(SubQueryExpression subQueryExpression, Express QueryMap[expression].SubQueryFullPath = subQueryFullPath; } + private static readonly HashSet SupportedTermsTypes = new HashSet + { + 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)Value).Select(x => x.ToString())); } - else if (PropertyType == typeof(Guid?)) - { - query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); - } - else if (PropertyType == typeof(int)) - { - query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); - } - else if (PropertyType == typeof(int?)) - { - query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); - } - else if (PropertyType == typeof(long)) - { - query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); - } - else if (PropertyType == typeof(long?)) - { - query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); - } - else if (PropertyType == typeof(double)) - { - query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); - } - else if(PropertyType == typeof(double?)) - { - query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); - } else if (PropertyType == typeof(DateTime)) { query = new TermsNode(PropertyName, @@ -372,14 +353,6 @@ private Node GetDifferentTypesTermsQueryNode() query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); } - else if (PropertyType == typeof(bool)) - { - query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); - } - else if (PropertyType == typeof(bool?)) - { - query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); - } else if (PropertyType == typeof(string)) { query = new TermsNode(PropertyName, (IEnumerable)Value);