Add syncing
This commit is contained in:
@ -142,10 +142,9 @@ func formatTagsForCombination(tags []string) string {
|
||||
return strings.Join(formatted, " ")
|
||||
}
|
||||
|
||||
func (ts *TimeSquire) GetIntervals(filter ...string) Intervals {
|
||||
ts.mutex.Lock()
|
||||
defer ts.mutex.Unlock()
|
||||
|
||||
// getIntervalsUnlocked fetches intervals without acquiring mutex (for internal use only).
|
||||
// Caller must hold ts.mutex.
|
||||
func (ts *TimeSquire) getIntervalsUnlocked(filter ...string) Intervals {
|
||||
args := append(ts.defaultArgs, "export")
|
||||
if filter != nil {
|
||||
args = append(args, filter...)
|
||||
@ -176,6 +175,14 @@ func (ts *TimeSquire) GetIntervals(filter ...string) Intervals {
|
||||
return intervals
|
||||
}
|
||||
|
||||
// GetIntervals fetches intervals with the given filter, acquiring mutex lock.
|
||||
func (ts *TimeSquire) GetIntervals(filter ...string) Intervals {
|
||||
ts.mutex.Lock()
|
||||
defer ts.mutex.Unlock()
|
||||
|
||||
return ts.getIntervalsUnlocked(filter...)
|
||||
}
|
||||
|
||||
func (ts *TimeSquire) StartTracking(tags []string) error {
|
||||
ts.mutex.Lock()
|
||||
defer ts.mutex.Unlock()
|
||||
@ -347,8 +354,8 @@ func (ts *TimeSquire) GetActive() *Interval {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get the active interval
|
||||
intervals := ts.GetIntervals()
|
||||
// Get the active interval using unlocked version (we already hold the mutex)
|
||||
intervals := ts.getIntervalsUnlocked()
|
||||
for _, interval := range intervals {
|
||||
if interval.End == "" {
|
||||
return interval
|
||||
|
||||
Reference in New Issue
Block a user