Skip to content

Commit

Permalink
move fetch to the chunks/transform
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Mar 13, 2023
1 parent 246c5a6 commit efcc5a3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
5 changes: 2 additions & 3 deletions cmd/slackdump/internal/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/rusq/slackdump/v2"
"github.com/rusq/slackdump/v2/auth"
"github.com/rusq/slackdump/v2/cmd/slackdump/internal/cfg"
"github.com/rusq/slackdump/v2/cmd/slackdump/internal/fetch"
"github.com/rusq/slackdump/v2/cmd/slackdump/internal/golang/base"
"github.com/rusq/slackdump/v2/internal/chunk/state"
"github.com/rusq/slackdump/v2/internal/chunk/transform"
Expand Down Expand Up @@ -128,7 +127,7 @@ func dumpv3(ctx context.Context, sess *slackdump.Session, list *structures.Entit

lg := dlog.FromContext(ctx)

p := &fetch.Parameters{
p := &transform.Parameters{
Oldest: time.Time(cfg.Oldest),
Latest: time.Time(cfg.Latest),
List: list,
Expand All @@ -149,7 +148,7 @@ func dumpv3(ctx context.Context, sess *slackdump.Session, list *structures.Entit
lg.Printf("fetching %q", link)

cr := trace.StartRegion(ctx, "fetch.Conversation")
statefile, err := fetch.Conversation(ctx, sess, tmpdir, link, p)
statefile, err := transform.Fetch(ctx, sess, tmpdir, link, p)
cr.End()
if err != nil {
return err
Expand Down
12 changes: 2 additions & 10 deletions export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (se *Export) exclusiveExport(ctx context.Context, uidx structures.UserIndex
}); err != nil {
return nil, fmt.Errorf("channels: error: %w", err)
}
se.l().Printf(" out of which exported: %d", len(chans))
se.lg.Printf(" out of which exported: %d", len(chans))
return chans, nil
}

Expand Down Expand Up @@ -257,16 +257,8 @@ func serialize(w io.Writer, data any) error {
return nil
}

// l returns the current logger or the default one if no logger is set.
func (se *Export) l() logger.Interface {
if se.lg == nil {
se.lg = logger.Default
}
return se.lg
}

// td outputs the message to trace and logs a debug message.
func (se *Export) td(ctx context.Context, category string, fmt string, a ...any) {
se.l().Debugf(fmt, a...)
se.lg.Debugf(fmt, a...)
trace.Logf(ctx, category, fmt, a...)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fetch
package transform

import (
"compress/gzip"
Expand Down Expand Up @@ -30,11 +30,11 @@ type streamer interface {

var replacer = strings.NewReplacer("/", "-", ":", "-")

// Conversation dumps a single conversation or thread into a directory,
// Fetch dumps a single conversation or thread into a directory,
// returning the name of the state file that was created. State file contains
// the information about the filename of the chunk recording file, as well as
// paths to downloaded files.
func Conversation(ctx context.Context, sess streamer, dir string, link string, p *Parameters) (string, error) {
func Fetch(ctx context.Context, sess streamer, dir string, link string, p *Parameters) (string, error) {
fileprefix := replacer.Replace(link)
var pattern = fmt.Sprintf("%s-*.jsonl.gz", fileprefix)
f, err := os.CreateTemp(dir, pattern)
Expand Down

0 comments on commit efcc5a3

Please sign in to comment.