Пример #1
0
func log(q Query, i *indexfile.IndexFile, bp *base.Positions, err *error) func() {
	start := time.Now()
	if q.base() {
		indexBaseLookupsStarted.Increment()
	} else {
		indexSetLookupsStarted.Increment()
	}
	return func() {
		duration := time.Since(start)
		if q.base() {
			indexBaseLookupsFinished.Increment()
			indexBaseLookupNanos.IncrementBy(duration.Nanoseconds())
		} else {
			indexSetLookupsFinished.Increment()
			indexSetLookupNanos.IncrementBy(duration.Nanoseconds())
		}
		v(3, "Query %q in %q took %v, found %d  %v", q, i.Name(), duration, len(*bp), *err)
	}
}
Пример #2
0
func (a timeQuery) LookupIn(ctx context.Context, index *indexfile.IndexFile) (bp base.Positions, err error) {
	defer log(a, index, &bp, &err)()
	last := filepath.Base(index.Name())
	intval, err := strconv.ParseInt(last, 10, 64)
	if err != nil {
		return nil, fmt.Errorf("could not parse basename %q: %v", last, err)
	}
	t := time.Unix(0, intval*1000) // converts micros -> nanos
	// Note, we add a minute when doing 'before' queries and subtract a minute
	// when doing 'after' queries, to make sure we actually get the time
	// specified.
	if !a[0].IsZero() && t.Before(a[0].Add(time.Minute)) {
		v(2, "time query skipping %q", index.Name())
		return base.NoPositions, nil
	}
	if !a[1].IsZero() && t.After(a[1].Add(-time.Minute)) {
		v(2, "time query skipping %q", index.Name())
		return base.NoPositions, nil
	}
	v(2, "time query using %q", index.Name())
	return base.AllPositions, nil
}