-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathevents.go
More file actions
114 lines (99 loc) · 3.25 KB
/
events.go
File metadata and controls
114 lines (99 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package featurevisor
// getParamsForDatafileSetEvent gets parameters for datafile set event
func getParamsForDatafileSetEvent(previousDatafileReader *DatafileReader, newDatafileReader *DatafileReader) LogDetails {
previousRevision := ""
if previousDatafileReader != nil {
previousRevision = previousDatafileReader.GetRevision()
}
newRevision := ""
if newDatafileReader != nil {
newRevision = newDatafileReader.GetRevision()
}
previousFeatureKeys := []string{}
if previousDatafileReader != nil {
previousFeatureKeys = previousDatafileReader.GetFeatureKeys()
}
newFeatureKeys := []string{}
if newDatafileReader != nil {
newFeatureKeys = newDatafileReader.GetFeatureKeys()
}
// Find removed features
removedFeatures := []string{}
for _, previousFeatureKey := range previousFeatureKeys {
found := false
for _, newFeatureKey := range newFeatureKeys {
if previousFeatureKey == newFeatureKey {
found = true
break
}
}
if !found {
removedFeatures = append(removedFeatures, previousFeatureKey)
}
}
// Find changed features
changedFeatures := []string{}
for _, previousFeatureKey := range previousFeatureKeys {
for _, newFeatureKey := range newFeatureKeys {
if previousFeatureKey == newFeatureKey {
// Check if feature was changed by comparing hashes
previousFeature := previousDatafileReader.GetFeature(FeatureKey(previousFeatureKey))
newFeature := newDatafileReader.GetFeature(FeatureKey(newFeatureKey))
if previousFeature != nil && newFeature != nil {
// Compare hashes if available, otherwise assume changed
if previousFeature.Hash != newFeature.Hash {
changedFeatures = append(changedFeatures, previousFeatureKey)
}
}
break
}
}
}
// Find added features
addedFeatures := []string{}
for _, newFeatureKey := range newFeatureKeys {
found := false
for _, previousFeatureKey := range previousFeatureKeys {
if newFeatureKey == previousFeatureKey {
found = true
break
}
}
if !found {
addedFeatures = append(addedFeatures, newFeatureKey)
}
}
// Combine all affected feature keys
allAffectedFeatures := append(append(removedFeatures, changedFeatures...), addedFeatures...)
return LogDetails{
"revision": newRevision,
"previousRevision": previousRevision,
"revisionChanged": previousRevision != newRevision,
"features": allAffectedFeatures,
}
}
// getParamsForStickySetEvent gets parameters for sticky set event
func getParamsForStickySetEvent(previousStickyFeatures StickyFeatures, newStickyFeatures StickyFeatures, replace bool) LogDetails {
keysBefore := make([]string, 0, len(previousStickyFeatures))
for key := range previousStickyFeatures {
keysBefore = append(keysBefore, string(key))
}
keysAfter := make([]string, 0, len(newStickyFeatures))
for key := range newStickyFeatures {
keysAfter = append(keysAfter, string(key))
}
// Get unique features affected (combine both sets and remove duplicates)
allKeys := append(keysBefore, keysAfter...)
uniqueFeaturesAffected := make([]string, 0)
seen := make(map[string]bool)
for _, key := range allKeys {
if !seen[key] {
seen[key] = true
uniqueFeaturesAffected = append(uniqueFeaturesAffected, key)
}
}
return LogDetails{
"features": uniqueFeaturesAffected,
"replaced": replace,
}
}