Repository: qdrant/qdrant
File: lib/collection/src/collection_manager/optimizers/mod.rs (Rust)

Code before:
        let mut completed = Vec::new();
        for tracker in self.descriptions.iter().rev() {
            let state = tracker.state.lock();
            match state.status {
                TrackerStatus::Optimizing => ongoing.push(tracker.progress_view.clone()),

                TrackerStatus::Done | TrackerStatus::Cancelled(_) | TrackerStatus::Error(_) => {
                    completed.push(tracker.progress_view.clone());
                }
            }
        }
        IndexingProgressViews { ongoing, completed }
    }
}

/// Tracks the state of an optimizer
#[derive(Clone, Debug)]
pub struct Tracker {
    /// Name of the optimizer
    pub name: String,
    /// Segment IDs being optimized
    pub segment_ids: Vec<SegmentId>,
    /// Segment UUIDs being optimized (same as segment_ids but filesystem aligned)
    pub segment_uuids: Vec<String>,
    /// Start time of the optimizer
    pub state: Arc<Mutex<TrackerState>>,
    /// A read-only view to progress tracker
    pub progress_view: ProgressView,
}

impl Tracker {
    /// Start a new optimizer tracker.
    ///
    /// Returns self (read-write) and a progress tracker (write-only).
    pub fn start(
        name: impl Into<String>,
        segment_ids: Vec<SegmentId>,
        segment_uuids: Vec<String>,
    ) -> (Tracker, ProgressTracker) {
        let (progress_view, progress_tracker) = new_progress_tracker();
        let tracker = Self {
            name: name.into(),
            segment_ids,
            segment_uuids,
            state: Default::default(),
            progress_view,
        };
        (tracker, progress_tracker)
    }

    /// Get handle to this tracker, allows updating state

Review comment (performance):
I can see how having these two versions of IDs could trip me up in the future. Maybe a more detailed comment would help.

```suggestion
   /// Internal segment IDs being optimized. 
   /// These are local and in-memory, meaning that they can refer to different segments after a service restart.
   pub segment_ids: Vec<SegmentId>,
    /// Segment UUIDs being optimized. 
    /// Refers to same segments as in `segment_ids`, but trackable across restarts, and reflect their directory name
    pub segment_uuids: Vec<String>,
```

Code after:
        let mut completed = Vec::new();
        for tracker in self.descriptions.iter().rev() {
            let state = tracker.state.lock();
            match state.status {
                TrackerStatus::Optimizing => ongoing.push(tracker.progress_view.clone()),

                TrackerStatus::Done | TrackerStatus::Cancelled(_) | TrackerStatus::Error(_) => {
                    completed.push(tracker.progress_view.clone());
                }
            }
        }
        IndexingProgressViews { ongoing, completed }
    }
}

/// Tracks the state of an optimizer
#[derive(Clone, Debug)]
pub struct Tracker {
    /// Name of the optimizer
    pub name: String,
    /// Internal segment IDs being optimized
    /// These are local and in-memory, meaning that they can refer to different segments after a service restart.
    pub segment_ids: Vec<SegmentId>,
    /// Segment UUIDs being optimized
    /// Refers to same segments as in `segment_ids`, but trackable across restarts, and reflect their directory name
    pub segment_uuids: Vec<String>,
    /// Start time of the optimizer
    pub state: Arc<Mutex<TrackerState>>,
    /// A read-only view to progress tracker
    pub progress_view: ProgressView,
}

impl Tracker {
    /// Start a new optimizer tracker.
    ///
    /// Returns self (read-write) and a progress tracker (write-only).
    pub fn start(
        name: impl Into<String>,
        segment_ids: Vec<SegmentId>,
        segment_uuids: Vec<String>,
    ) -> (Tracker, ProgressTracker) {
        let (progress_view, progress_tracker) = new_progress_tracker();
        let tracker = Self {
            name: name.into(),
            segment_ids,
            segment_uuids,
            state: Default::default(),
            progress_view,
        };
        (tracker, progress_tracker)
    }