// pruneInterval calculates the prune interval. This is a function of the
// cache's AccessUpdateInterval and PruneFactor.
//
// If either AccessUpdateInterval or PruneFactor is <= 0, this will return 0,
// indicating no prune interval.
434586
func (cache *Cache) pruneInterval() time.Duration {
	if cache.AccessUpdateInterval > 0 && cache.PruneFactor > 0 {
		return cache.AccessUpdateInterval * time.Duration(1+cache.PruneFactor)
	}
	return 0
}
893677
func (_m *SchedulerQueueClient) QueryIntervalByName(intervalName string) (models.Interval, error) {
	ret := _m.Called(intervalName)

	var r0 models.Interval
	if rf, ok := ret.Get(0).(func(string) models.Interval); ok {
		r0 = rf(intervalName)
	} else {
		r0 = ret.Get(0).(models.Interval)
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(string) error); ok {
		r1 = rf(intervalName)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
164224
func (s *Store) Prune(ctx context.Context, prefix string) error {
	path := filepath.Join(s.path, filepath.Clean(prefix))
	out.Debug(ctx, "fs.Prune(%s) - %s", prefix, path)
	return os.RemoveAll(path)
}
1061709
func (s *Thumbnails) SetInterval(v string) *Thumbnails {
	s.Interval = &v
	return s
}
746363
func (a *HistogramAggregation) Interval(interval float64) *HistogramAggregation {
	a.interval = interval
	return a
}
349237
func (c *client) prunePerAccountCache() {
	n := 0
	for cacheKey := range c.in.pacache {
		delete(c.in.pacache, cacheKey)
		if n++; n > prunePerAccountCacheSize {
			break
		}
	}
}
1113196
func (b *BlockedEvals) pruneUnblockIndexes() {
	b.l.Lock()
	defer b.l.Unlock()

	if b.timetable == nil {
		return
	}

	cutoff := time.Now().UTC().Add(-1 * pruneThreshold)
	oldThreshold := b.timetable.NearestIndex(cutoff)

	for key, index := range b.unblockIndexes {
		if index < oldThreshold {
			delete(b.unblockIndexes, key)
		}
	}
}
932000
func (c *Client) UpdateInterval(from contract.Interval) (err error) {
	check, err := c.IntervalByName(from.Name)
	if err != nil && err != redis.ErrNil {
		return err
	}
	if err == nil && from.ID != check.ID {
		// IDs are different -> name not unique
		return db.ErrNotUnique
	}

	from.Timestamps.Modified = db.MakeTimestamp()
	err = mergo.Merge(&from, check)
	if err != nil {
		return err
	}

	interval := models.NewInterval(from)
	data, err := json.Marshal(interval)
	if err != nil {
		return err
	}

	conn := c.Pool.Get()
	defer conn.Close()

	_ = conn.Send("MULTI")
	deleteObject(interval, interval.ID, conn)
	addObject(data, interval, interval.ID, conn)
	_, err = conn.Do("EXEC")

	return err
}
486623
func (m *UnpartitionedMemoryIdx) Prune(now time.Time) ([]idx.Archive, error) {
	log.Info("memory-idx: start pruning of series across all orgs")
	orgs := make(map[uint32]struct{})
	m.RLock()
	for org := range m.tree {
		orgs[org] = struct{}{}
	}
	if TagSupport {
		for org := range m.tags {
			orgs[org] = struct{}{}
		}
	}
	m.RUnlock()

	var pruned []idx.Archive
	toPruneUntagged := make(map[uint32]map[string]struct{}, len(orgs))
	toPruneTagged := make(map[uint32]IdSet, len(orgs))
	for org := range orgs {
		toPruneTagged[org] = make(IdSet)
		toPruneUntagged[org] = make(map[string]struct{})
	}
	pre := time.Now()

	// getting all cutoffs once saves having to recompute everytime we have a match
	cutoffs := IndexRules.Cutoffs(now)

	m.RLock()

DEFS:
	for _, def := range m.defById {
		cutoff := cutoffs[def.IrId]
		if atomic.LoadInt64(&def.LastUpdate) >= cutoff {
			continue DEFS
		}

		if len(def.Tags) == 0 {
			tree, ok := m.tree[def.OrgId]
			if !ok {
				continue DEFS
			}

			n, ok := tree.Items[def.Name]
			if !ok || !n.Leaf() {
				continue DEFS
			}

			for _, id := range n.Defs {
				if atomic.LoadInt64(&m.defById[id].LastUpdate) >= cutoff {
					continue DEFS
				}
			}

			toPruneUntagged[def.OrgId][n.Path] = struct{}{}
		} else {
			defs := m.defByTagSet.defs(def.OrgId, def.NameWithTags())
			// if any other MetricDef with the same tag set is not expired yet,
			// then we do not want to prune any of them
			for def := range defs {
				if atomic.LoadInt64(&def.LastUpdate) >= cutoff {
					continue DEFS
				}
			}

			for def := range defs {
				toPruneTagged[def.OrgId][def.Id] = struct{}{}
			}
		}
	}
	m.RUnlock()

	// create a new timeLimiter that allows us to limit the amount of time we spend
	// holding a lock to maxPruneLockTime (default 100ms) every second.
	tl := NewTimeLimiter(time.Second, maxPruneLockTime, time.Now())

	for org, ids := range toPruneTagged {
		if len(ids) == 0 {
			continue
		}
		// make sure we are not locking for too long.
		tl.Wait()
		lockStart := time.Now()
		m.Lock()
		defs := m.deleteTaggedByIdSet(org, ids)
		m.Unlock()
		tl.Add(time.Since(lockStart))
		pruned = append(pruned, defs...)
	}

ORGS:
	for org, paths := range toPruneUntagged {
		if len(paths) == 0 {
			continue
		}

		for path := range paths {
			tl.Wait()
			lockStart := time.Now()
			m.Lock()
			tree, ok := m.tree[org]

			if !ok {
				m.Unlock()
				tl.Add(time.Since(lockStart))
				continue ORGS
			}

			n, ok := tree.Items[path]

			if !ok {
				m.Unlock()
				tl.Add(time.Since(lockStart))
				log.Debugf("memory-idx: series %s for orgId:%d was identified for pruning but cannot be found.", path, org)
				continue
			}

			log.Debugf("memory-idx: series %s for orgId:%d is stale. pruning it.", n.Path, org)
			defs := m.delete(org, n, true, false)
			m.Unlock()
			tl.Add(time.Since(lockStart))
			pruned = append(pruned, defs...)
		}
		if m.findCache != nil {
			if len(paths) > findCacheInvalidateQueueSize {
				m.findCache.Purge(org)
			} else {
				for path := range paths {
					m.findCache.InvalidateFor(org, path)
				}
			}
		}
	}

	statMetricsActive.Set(len(m.defById))

	duration := time.Since(pre)
	log.Infof("memory-idx: finished pruning of %d series in %s", len(pruned), duration)

	statPruneDuration.Value(duration)
	return pruned, nil
}
48788
func (s *TimeBasedCanary) SetCanaryInterval(v int64) *TimeBasedCanary {
	s.CanaryInterval = &v
	return s
}
406946
func (tm *Timer) SetInterval(ns time.Duration) {
	tm.interval.Set(ns)
	tm.mu.Lock()
	defer tm.mu.Unlock()
	if tm.running {
		tm.msg <- timerReset
	}
}
112556
func ToInterval(ls orb.LineString, df orb.DistanceFunc, dist float64) orb.LineString {
	if dist <= 0 {
		return nil
	}

	// precomputes the total distance and intermediate distances
	total, dists := precomputeDistances(ls, df)

	totalPoints := int(total/dist) + 1
	ls, ret := resampleEdgeCases(ls, totalPoints)
	if ret {
		return ls
	}

	return resample(ls, dists, total, totalPoints)
}
760288
func isIntervalStillInUse(s contract.Interval) (bool, error) {
	var intervalActions []contract.IntervalAction

	intervalActions, err := dbClient.IntervalActionsByIntervalName(s.Name)
	if err != nil {
		return false, err
	}
	if len(intervalActions) > 0 {
		return true, nil
	}

	return false, nil
}
1326894
func (c *ContainerCache) Prune(liveContainers map[string]interface{}) {
	c.Lock()
	defer c.Unlock()

	for id := range c.cache {
		if _, ok := liveContainers[id]; !ok {
			delete(c.cache, id)
		}
	}
}
182308
func (s *Store) Prune(ctx context.Context, tree string) error {
	return s.delete(ctx, tree, true)
}
1127489
func WithRefreshInterval(value time.Duration) coptions.Opt {
	return func(p coptions.Params) {
		logger.Debug("Checking refreshIntervalSetter")
		if setter, ok := p.(refreshIntervalSetter); ok {
			setter.SetDiscoveryRefreshInterval(value)
		}
	}
}
73728
func (s *DvbTdtSettings) SetTdtInterval(v int64) *DvbTdtSettings {
	s.TdtInterval = &v
	return s
}