@@ -10,24 +10,30 @@ namespace Nest
10
10
{
11
11
internal class ResolvedRouteValues : Dictionary < string , string >
12
12
{
13
+ internal static ResolvedRouteValues Empty = new ( 0 ) ;
13
14
15
+ public ResolvedRouteValues ( int size ) : base ( size ) { }
14
16
}
15
17
16
18
public class RouteValues : Dictionary < string , IUrlParameter >
17
19
{
18
- // Not too happy with this, only exists because IndexRequest needs a resolved
19
- // id to know if it has to send a PUT or POST.
20
- internal ResolvedRouteValues Resolved { get ; private set ; }
20
+ /// <summary>
21
+ /// Used specifically by index requests to determine whether to use PUT or POST.
22
+ /// </summary>
23
+ internal bool ContainsId { get ; private set ; }
21
24
22
25
internal ResolvedRouteValues Resolve ( IConnectionSettingsValues configurationValues )
23
26
{
24
- var resolved = new ResolvedRouteValues ( ) ;
27
+ if ( Count == 0 ) return ResolvedRouteValues . Empty ;
28
+
29
+ var resolved = new ResolvedRouteValues ( Count ) ;
25
30
foreach ( var kv in this )
26
31
{
27
32
var value = this [ kv . Key ] . GetString ( configurationValues ) ;
28
- if ( ! value . IsNullOrEmpty ( ) ) resolved [ kv . Key ] = value ;
33
+ if ( value . IsNullOrEmpty ( ) ) continue ;
34
+ resolved [ kv . Key ] = value ;
35
+ if ( IsId ( kv . Key ) ) ContainsId = true ;
29
36
}
30
- Resolved = resolved ;
31
37
return resolved ;
32
38
}
33
39
@@ -36,19 +42,20 @@ private RouteValues Route(string name, IUrlParameter routeValue, bool required =
36
42
switch ( routeValue ) {
37
43
case null when ! required : {
38
44
if ( ! ContainsKey ( name ) ) return this ;
39
-
40
45
Remove ( name ) ;
41
- Resolved = null ; //invalidate cache
46
+ if ( IsId ( name ) ) ContainsId = false ; // invalidate cache
42
47
return this ;
43
48
}
44
49
case null : throw new ArgumentNullException ( name , $ "{ name } is required to build a url to this API") ;
45
50
default :
46
51
this [ name ] = routeValue ;
47
- Resolved = null ; //invalidate cache
52
+ if ( IsId ( name ) ) ContainsId = false ; // invalidate cache
48
53
return this ;
49
54
}
50
55
}
51
56
57
+ private static bool IsId ( string key ) => key . Equals ( "id" , StringComparison . OrdinalIgnoreCase ) ;
58
+
52
59
internal RouteValues Required ( string route , IUrlParameter value ) => Route ( route , value ) ;
53
60
54
61
internal RouteValues Optional ( string route , IUrlParameter value ) => Route ( route , value , false ) ;
0 commit comments