@@ -18,41 +18,39 @@ public void UpdateUserPinProgress(Dictionary<long, int> pinProgressUpdates, Game
18
18
( long ) ServerPins . TopXOfAnyCommunityLevelWithOver50Scores ,
19
19
] ;
20
20
21
- this . Write ( ( ) =>
21
+ foreach ( KeyValuePair < long , int > pinProgressUpdate in pinProgressUpdates )
22
22
{
23
- foreach ( KeyValuePair < long , int > pinProgressUpdate in pinProgressUpdates )
24
- {
25
- long pinId = pinProgressUpdate . Key ;
26
- int newProgress = pinProgressUpdate . Value ;
27
- PinProgressRelation ? existingProgress = existingProgresses . FirstOrDefault ( p => p . PinId == pinId ) ;
23
+ long pinId = pinProgressUpdate . Key ;
24
+ int newProgress = pinProgressUpdate . Value ;
25
+ PinProgressRelation ? existingProgress = existingProgresses . FirstOrDefault ( p => p . PinId == pinId ) ;
28
26
29
- if ( existingProgress == null )
30
- {
31
- PinProgressRelation newRelation = new ( )
32
- {
33
- PinId = pinId ,
34
- Progress = newProgress ,
35
- Publisher = user ,
36
- FirstPublished = now ,
37
- LastUpdated = now ,
38
- IsBeta = isBeta ,
39
- } ;
40
- this . PinProgressRelations . Add ( newRelation ) ;
41
- continue ;
42
- }
43
-
44
- bool isSpecialTreatmentPin = descendingProgressPins . Contains ( pinId ) ;
45
-
46
- // Only update progress if it's better. For most pins it's better the greater it is, but for the pins in
47
- // specialTreatmentPins, it's better the smaller it is.
48
- if ( ! isSpecialTreatmentPin && newProgress > existingProgress . Progress
49
- || isSpecialTreatmentPin && newProgress < existingProgress . Progress )
27
+ if ( existingProgress == null )
28
+ {
29
+ PinProgressRelation newRelation = new ( )
50
30
{
51
- existingProgress . Progress = newProgress ;
52
- existingProgress . LastUpdated = now ;
53
- }
31
+ PinId = pinId ,
32
+ Progress = newProgress ,
33
+ Publisher = user ,
34
+ FirstPublished = now ,
35
+ LastUpdated = now ,
36
+ IsBeta = isBeta ,
37
+ } ;
38
+ this . PinProgressRelations . Add ( newRelation ) ;
39
+ continue ;
40
+ }
41
+
42
+ bool isSpecialTreatmentPin = descendingProgressPins . Contains ( pinId ) ;
43
+
44
+ // Only update progress if it's better. For most pins it's better the greater it is, but for the pins in
45
+ // specialTreatmentPins, it's better the smaller it is.
46
+ if ( ( ! isSpecialTreatmentPin && newProgress > existingProgress . Progress )
47
+ || ( isSpecialTreatmentPin && newProgress < existingProgress . Progress ) )
48
+ {
49
+ existingProgress . Progress = newProgress ;
50
+ existingProgress . LastUpdated = now ;
54
51
}
55
- } ) ;
52
+ }
53
+ this . SaveChanges ( ) ;
56
54
}
57
55
58
56
public void UpdateUserProfilePins ( List < long > pinUpdates , GameUser user , TokenGame game )
@@ -61,40 +59,38 @@ public void UpdateUserProfilePins(List<long> pinUpdates, GameUser user, TokenGam
61
59
IEnumerable < ProfilePinRelation > existingProfilePins = this . GetProfilePinsByUser ( user , game ) ;
62
60
DateTimeOffset now = this . _time . Now ;
63
61
64
- this . Write ( ( ) =>
62
+ for ( int i = 0 ; i < pinUpdates . Count ; i ++ )
65
63
{
66
- for ( int i = 0 ; i < pinUpdates . Count ; i ++ )
67
- {
68
- long progressType = pinUpdates [ i ] ;
64
+ long progressType = pinUpdates [ i ] ;
69
65
70
- // Does the user have any progress on the new pin?
71
- if ( ! existingProgressIds . Contains ( progressType ) ) continue ;
66
+ // Does the user have any progress on the new pin?
67
+ if ( ! existingProgressIds . Contains ( progressType ) ) continue ;
72
68
73
- ProfilePinRelation ? existingPinAtIndex = existingProfilePins . FirstOrDefault ( p => p . Index == i ) ;
69
+ ProfilePinRelation ? existingPinAtIndex = existingProfilePins . FirstOrDefault ( p => p . Index == i ) ;
74
70
75
- // If the pin at this position hasn't changed, skip it
76
- if ( existingPinAtIndex ? . PinId == progressType ) continue ;
71
+ // If the pin at this position hasn't changed, skip it
72
+ if ( existingPinAtIndex ? . PinId == progressType ) continue ;
77
73
78
- if ( existingPinAtIndex == null )
79
- {
80
- this . ProfilePinRelations . Add ( new ( )
81
- {
82
- PinId = progressType ,
83
- Publisher = user ,
84
- PublisherId = user . UserId ,
85
- Index = i ,
86
- Game = game ,
87
- Timestamp = now ,
88
- } ) ;
89
- }
90
- else
74
+ if ( existingPinAtIndex == null )
75
+ {
76
+ this . ProfilePinRelations . Add ( new ( )
91
77
{
92
- this . ProfilePinRelations . Update ( existingPinAtIndex ) ;
93
- existingPinAtIndex . PinId = progressType ;
94
- existingPinAtIndex . Timestamp = now ; // New pin at this position: reset timestamp
95
- }
78
+ PinId = progressType ,
79
+ Publisher = user ,
80
+ PublisherId = user . UserId ,
81
+ Index = i ,
82
+ Game = game ,
83
+ Timestamp = now ,
84
+ } ) ;
96
85
}
97
- } ) ;
86
+ else
87
+ {
88
+ this . ProfilePinRelations . Update ( existingPinAtIndex ) ;
89
+ existingPinAtIndex . PinId = progressType ;
90
+ existingPinAtIndex . Timestamp = now ; // New pin at this position: reset timestamp
91
+ }
92
+ }
93
+ this . SaveChanges ( ) ;
98
94
}
99
95
100
96
public PinProgressRelation UpdateUserPinProgressToLowest ( long pinId , int newProgressValue , GameUser user , bool isBeta )
@@ -105,53 +101,43 @@ public PinProgressRelation UpdateUserPinProgressToLowest(long pinId, int newProg
105
101
106
102
if ( progressToUpdate == null )
107
103
{
108
- this . Write ( ( ) =>
104
+ progressToUpdate = new ( )
109
105
{
110
- progressToUpdate = new ( )
111
- {
112
- PinId = pinId ,
113
- Progress = newProgressValue ,
114
- Publisher = user ,
115
- PublisherId = user . UserId ,
116
- FirstPublished = now ,
117
- LastUpdated = now ,
118
- IsBeta = isBeta ,
119
- } ;
106
+ PinId = pinId ,
107
+ Progress = newProgressValue ,
108
+ Publisher = user ,
109
+ PublisherId = user . UserId ,
110
+ FirstPublished = now ,
111
+ LastUpdated = now ,
112
+ IsBeta = isBeta ,
113
+ } ;
120
114
121
- this . PinProgressRelations . Add ( progressToUpdate ) ;
122
- } ) ;
115
+ this . PinProgressRelations . Add ( progressToUpdate ) ;
116
+ SaveChanges ( ) ;
123
117
}
124
118
// Only update if the final progress value is actually lower to the one already set
125
119
else if ( newProgressValue < progressToUpdate . Progress )
126
120
{
127
- this . Write ( ( ) =>
128
- {
129
- progressToUpdate . Progress = newProgressValue ;
130
- progressToUpdate . LastUpdated = now ;
131
- } ) ;
121
+ progressToUpdate . Progress = newProgressValue ;
122
+ progressToUpdate . LastUpdated = now ;
123
+ SaveChanges ( ) ;
132
124
}
133
125
134
126
return progressToUpdate ! ;
135
127
}
136
128
137
129
public void IncrementUserPinProgress ( long pinId , int progressToAdd , GameUser user )
138
130
{
139
- this . Write ( ( ) =>
140
- {
141
- this . IncrementUserPinProgressInternal ( pinId , progressToAdd , user , true ) ;
142
- this . IncrementUserPinProgressInternal ( pinId , progressToAdd , user , false ) ;
143
- } ) ;
144
-
131
+ this . IncrementUserPinProgressInternal ( pinId , progressToAdd , user , true ) ;
132
+ this . IncrementUserPinProgressInternal ( pinId , progressToAdd , user , false ) ;
133
+
134
+ this . SaveChanges ( ) ;
145
135
}
146
136
147
137
public PinProgressRelation IncrementUserPinProgress ( long pinId , int progressToAdd , GameUser user , bool isBeta )
148
138
{
149
- PinProgressRelation relation = null ! ;
150
-
151
- this . Write ( ( ) =>
152
- {
153
- relation = this . IncrementUserPinProgressInternal ( pinId , progressToAdd , user , isBeta ) ;
154
- } ) ;
139
+ PinProgressRelation relation = this . IncrementUserPinProgressInternal ( pinId , progressToAdd , user , isBeta ) ;
140
+ this . SaveChanges ( ) ;
155
141
156
142
return relation ;
157
143
}
@@ -180,7 +166,7 @@ private PinProgressRelation IncrementUserPinProgressInternal(long pinId, int pro
180
166
}
181
167
else
182
168
{
183
- progressToUpdate . Progress = + progressToAdd ;
169
+ progressToUpdate . Progress += progressToAdd ;
184
170
progressToUpdate . LastUpdated = now ;
185
171
}
186
172
0 commit comments