diff --git a/internal/chunk/chunk.go b/internal/chunk/chunk.go index 4afad3ff..1c101d76 100644 --- a/internal/chunk/chunk.go +++ b/internal/chunk/chunk.go @@ -85,6 +85,13 @@ const ( chanInfoPrefix = "ic" ) +// Chunk ID categories +const ( + catFile = 'f' + catInfo = 'i' + catList = 'l' +) + // ID returns a Group ID for the chunk. func (c *Chunk) ID() GroupID { switch c.Type { @@ -145,3 +152,13 @@ func (c *Chunk) messageTimestamps() ([]int64, error) { } return ts, nil } + +// isInfo returns true, if the chunk is an info chunk. +func (g GroupID) isInfo() bool { + return g[0] == catInfo +} + +// isList returns true, if the chunk is a list chunk. +func (g GroupID) isList() bool { + return g[0] == catList +} diff --git a/internal/chunk/file.go b/internal/chunk/file.go index 98564445..3a668a64 100644 --- a/internal/chunk/file.go +++ b/internal/chunk/file.go @@ -83,6 +83,7 @@ type decoder interface { func indexChunks(dec decoder) (index, error) { idx := make(index, 200) // buffer for 200 chunks to avoid reallocations. + var id GroupID for i := 0; ; i++ { offset := dec.InputOffset() // record current offset @@ -93,7 +94,8 @@ func indexChunks(dec decoder) (index, error) { } return nil, err } - idx[chunk.ID()] = append(idx[chunk.ID()], offset) + id = chunk.ID() + idx[id] = append(idx[id], offset) } return idx, nil } @@ -238,7 +240,7 @@ func (p *File) AllChannelInfos() ([]slack.Channel, error) { if len(id) == 0 { return nil, fmt.Errorf("internal error: invalid id: %q", id) } - if id[0] == 'i' && id[1] == 'c' { + if strings.HasPrefix(string(id), chanInfoPrefix) { offsets = append(offsets, off...) } } @@ -247,6 +249,7 @@ func (p *File) AllChannelInfos() ([]slack.Channel, error) { }) } +// int64s implements sort.Interface for []int64. type int64s []int64 func (a int64s) Len() int { return len(a) } @@ -322,7 +325,7 @@ func (p *File) AllChannelIDs() []string { var ids = make([]string, 0, 1) for gid := range p.idx { id := string(gid) - if !strings.Contains(id, ":") && id[0] != 'i' && id[0] != 'l' { + if !strings.Contains(id, ":") && !gid.isInfo() && !gid.isList() { ids = append(ids, id) } } @@ -357,7 +360,7 @@ func (f *File) offsetTimestamps() (offts, error) { var ret = make(offts, f.idx.OffsetCount()) for id, offsets := range f.idx { switch id[0] { - case 'i', 'f', 'l': // ignoring files, information and list chunks + case catInfo, catFile, catList: // ignoring files, information and list chunks continue } for _, offset := range offsets { @@ -408,8 +411,6 @@ func (f *File) Sorted(ctx context.Context, desc bool, fn func(ts time.Time, m *s ctx, task := trace.NewTask(ctx, "file.Sorted") defer task.End() - trace.Log(ctx, "mutex", "lock") - rgnOt := trace.StartRegion(ctx, "offsetTimestamps") ots, err := f.offsetTimestamps() rgnOt.End()