File tree Expand file tree Collapse file tree 1 file changed +40
-1
lines changed Expand file tree Collapse file tree 1 file changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -186,4 +186,43 @@ def get_dict(
186186 else :
187187 grouped_activity_log [suggestion_id ] = [event ]
188188
189- return grouped_activity_log
189+ # Second pass to fold repeated package actions by user,
190+ # needed because with htmx we're sending item-wise changes that we still want to display in bulk
191+ folded_activity_log = {}
192+ for suggestion_id , events in grouped_activity_log .items ():
193+ suggestion_log = []
194+
195+ accumulator = None
196+ for event in events :
197+ if not event ["action" ].startswith ("derivations" ):
198+ if accumulator :
199+ suggestion_log .append (accumulator )
200+ accumulator = None
201+ suggestion_log .append (event )
202+ else :
203+ if not accumulator :
204+ accumulator = event
205+ else :
206+ if (
207+ event ["action" ] == accumulator ["action" ]
208+ and event ["username" ] == accumulator ["username" ]
209+ ):
210+ accumulator ["package_names" ] = (
211+ accumulator ["package_names" ] + event ["package_names" ]
212+ )
213+ accumulator ["package_count" ] = (
214+ accumulator ["package_count" ] + event ["package_count" ]
215+ )
216+ accumulator ["timestamp" ] = event [
217+ "timestamp"
218+ ] # Keep latest timestamp
219+ else :
220+ suggestion_log .append (accumulator )
221+ accumulator = event
222+
223+ if accumulator :
224+ suggestion_log .append (accumulator )
225+
226+ folded_activity_log [suggestion_id ] = suggestion_log
227+
228+ return folded_activity_log
You can’t perform that action at this time.
0 commit comments