Skip to content

Commit

Permalink
Update tasks.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobench committed Nov 4, 2024
1 parent 7eb7dc4 commit ebf0706
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions stats-backend/api2/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1854,3 +1854,14 @@ def bulk_update_node_statuses(nodes_data):

# Bulk create status history
NodeStatusHistory.objects.bulk_create(status_history_to_create)

#Clean up duplicate consecutive statuses !IMPORTANT KEEP HERE FOR NOW
subquery = NodeStatusHistory.objects.filter(
node_id=OuterRef('node_id'),
timestamp__lt=OuterRef('timestamp')
).order_by('-timestamp')

duplicate_records = NodeStatusHistory.objects.annotate(
prev_status=Subquery(subquery.values('is_online')[:1])
).filter(is_online=F('prev_status'))
duplicate_records.delete()

0 comments on commit ebf0706

Please sign in to comment.