@@ -26,29 +26,29 @@ type distinctValuesCache struct {
26
26
// already cached, it returns the cached values. If not, it loads the values from the given load
27
27
// function and caches them. The last dataset is never cached, so it is always loaded from the
28
28
// load function. The load function is called with the missing datasets and the last dataset.
29
- func (dpc * distinctValuesCache ) GetDistinctValues (key string , datasets []string , load func (datasets []string ) (map [string ][]string , error )) ([]string , error ) {
29
+ func (dvc * distinctValuesCache ) GetDistinctValues (key string , datasets []string , load func (datasets []string ) (map [string ][]string , error )) ([]string , error ) {
30
30
// First check if we are missing any datasets from the cache.
31
31
// If we are, we need to load them along with the last dataset
32
32
// The last dataset is never cached, so we need to load it every time
33
- dpc .cacheMu .RLock ()
34
- missing := dpc .missing (key , datasets [:len (datasets )- 1 ])
35
- dpc .cacheMu .RUnlock ()
33
+ dvc .cacheMu .RLock ()
34
+ missing := dvc .missing (key , datasets [:len (datasets )- 1 ])
35
+ dvc .cacheMu .RUnlock ()
36
36
37
37
// If we are missing any datasets, we need to lock the key, so that
38
38
// we don't load the same datasets multiple times for the same key.
39
39
// This lock needs to be retained until the datasets are loaded into the cache.
40
40
if len (missing ) > 0 {
41
- dpc .klock .Lock (key )
41
+ dvc .klock .Lock (key )
42
42
// Check again if we are missing any datasets, to deal with race conditions
43
- dpc .cacheMu .Lock ()
44
- missing = dpc .missing (key , datasets [:len (datasets )- 1 ])
45
- if _ , ok := dpc .cache [key ]; ! ok {
46
- dpc .cache [key ] = make (map [string ][]string )
43
+ dvc .cacheMu .Lock ()
44
+ missing = dvc .missing (key , datasets [:len (datasets )- 1 ])
45
+ if _ , ok := dvc .cache [key ]; ! ok {
46
+ dvc .cache [key ] = make (map [string ][]string )
47
47
}
48
- dpc .cacheMu .Unlock ()
48
+ dvc .cacheMu .Unlock ()
49
49
if len (missing ) == 0 {
50
50
// If we are not missing any datasets, we need to unlock the key
51
- dpc .klock .Unlock (key )
51
+ dvc .klock .Unlock (key )
52
52
}
53
53
}
54
54
@@ -59,25 +59,25 @@ func (dpc *distinctValuesCache) GetDistinctValues(key string, datasets []string,
59
59
}
60
60
// if we were missing any datasets, we need to add them to the cache and unlock the key
61
61
if len (missing ) > 0 {
62
- dpc .cacheMu .Lock ()
62
+ dvc .cacheMu .Lock ()
63
63
for _ , ds := range missing {
64
- dpc .cache [key ][ds ] = results [ds ]
64
+ dvc .cache [key ][ds ] = results [ds ]
65
65
}
66
- dpc .cacheMu .Unlock ()
67
- dpc .klock .Unlock (key )
66
+ dvc .cacheMu .Unlock ()
67
+ dvc .klock .Unlock (key )
68
68
}
69
69
70
70
// Now we need to get values for all the datasets requested so that we can calculate
71
71
// the distinct values.
72
72
// We already have some values in the results map (last dataset & missing), so we only need to fill in
73
73
// the rest of the datasets from the cache.
74
- dpc .cacheMu .RLock ()
74
+ dvc .cacheMu .RLock ()
75
75
for _ , ds := range datasets {
76
76
if _ , ok := results [ds ]; ! ok {
77
- results [ds ] = dpc .cache [key ][ds ]
77
+ results [ds ] = dvc .cache [key ][ds ]
78
78
}
79
79
}
80
- dpc .cacheMu .RUnlock ()
80
+ dvc .cacheMu .RUnlock ()
81
81
82
82
// Calculating distinct values is easy, we just need to
83
83
// iterate over all the datasets and add them to a map
@@ -92,17 +92,17 @@ func (dpc *distinctValuesCache) GetDistinctValues(key string, datasets []string,
92
92
}
93
93
94
94
// RemoveDataset removes the dataset from the cache for all keys.
95
- func (dpc * distinctValuesCache ) RemoveDataset (dataset string ) {
96
- dpc .cacheMu .Lock ()
97
- defer dpc .cacheMu .Unlock ()
98
- for key := range dpc .cache {
99
- delete (dpc .cache [key ], dataset )
95
+ func (dvc * distinctValuesCache ) RemoveDataset (dataset string ) {
96
+ dvc .cacheMu .Lock ()
97
+ defer dvc .cacheMu .Unlock ()
98
+ for key := range dvc .cache {
99
+ delete (dvc .cache [key ], dataset )
100
100
}
101
101
}
102
102
103
- func (dpc * distinctValuesCache ) missing (key string , datasets []string ) []string {
103
+ func (dvc * distinctValuesCache ) missing (key string , datasets []string ) []string {
104
104
var missing []string
105
- dscache , ok := dpc .cache [key ]
105
+ dscache , ok := dvc .cache [key ]
106
106
if ! ok {
107
107
return datasets
108
108
}
0 commit comments