fix: batch upload to HRDLog instead of one by one
This commit is contained in:
@@ -5223,12 +5223,15 @@ func (a *App) runManualUpload(svc extsvc.Service, ids []int64, cfg extsvc.Extern
|
||||
}
|
||||
emit(fmt.Sprintf("LoTW: %d QSO(s) uploaded", uploaded))
|
||||
}
|
||||
} else if svc == extsvc.ServiceClublog {
|
||||
// Club Log accepts a whole ADIF file (putlogs.php) and dedupes
|
||||
// server-side, so upload in chunks instead of one realtime.php request
|
||||
// per QSO. Chunked so a single failure doesn't lose the whole run and
|
||||
// the user sees progress.
|
||||
const clublogChunk = 100
|
||||
} else if svc == extsvc.ServiceClublog || svc == extsvc.ServiceHRDLog {
|
||||
// Club Log and HRDLog both accept a whole ADIF document in one request
|
||||
// and dedupe server-side, so upload in chunks instead of one request per
|
||||
// QSO. Chunked so a single failure doesn't lose the whole run and the
|
||||
// user sees progress.
|
||||
name, chunk := "Club Log", 100
|
||||
if svc == extsvc.ServiceHRDLog {
|
||||
name, chunk = "HRDLog", 50
|
||||
}
|
||||
type item struct {
|
||||
id int64
|
||||
rec string
|
||||
@@ -5248,9 +5251,9 @@ func (a *App) runManualUpload(svc extsvc.Service, ids []int64, cfg extsvc.Extern
|
||||
}
|
||||
items = append(items, item{id: id, rec: rec, call: call})
|
||||
}
|
||||
emit(fmt.Sprintf("Club Log: uploading %d QSO(s) in batches of %d…", len(items), clublogChunk))
|
||||
for start := 0; start < len(items); start += clublogChunk {
|
||||
end := start + clublogChunk
|
||||
emit(fmt.Sprintf("%s: uploading %d QSO(s) in batches of %d…", name, len(items), chunk))
|
||||
for start := 0; start < len(items); start += chunk {
|
||||
end := start + chunk
|
||||
if end > len(items) {
|
||||
end = len(items)
|
||||
}
|
||||
@@ -5260,19 +5263,25 @@ func (a *App) runManualUpload(svc extsvc.Service, ids []int64, cfg extsvc.Extern
|
||||
recs[i] = it.rec
|
||||
}
|
||||
doc := adif.BatchRecordsADIF(recs)
|
||||
res, err := extsvc.UploadClublogADIF(ctx, nil, cfg.Clublog, doc)
|
||||
var res extsvc.UploadResult
|
||||
var err error
|
||||
if svc == extsvc.ServiceHRDLog {
|
||||
res, err = extsvc.UploadHRDLogADIF(ctx, nil, cfg.HRDLog.Callsign, cfg.HRDLog.Code, doc)
|
||||
} else {
|
||||
res, err = extsvc.UploadClublogADIF(ctx, nil, cfg.Clublog, doc)
|
||||
}
|
||||
if err == nil && res.OK {
|
||||
for _, it := range batch {
|
||||
a.markExtUploaded(svc, it.id, "")
|
||||
uploaded++
|
||||
}
|
||||
emit(fmt.Sprintf("Club Log: %d/%d uploaded", end, len(items)))
|
||||
emit(fmt.Sprintf("%s: %d/%d uploaded", name, end, len(items)))
|
||||
} else {
|
||||
msg := res.Message
|
||||
if err != nil {
|
||||
msg = err.Error()
|
||||
}
|
||||
emit(fmt.Sprintf("Club Log: batch of %d FAILED: %s", len(batch), msg))
|
||||
emit(fmt.Sprintf("%s: batch of %d FAILED: %s", name, len(batch), msg))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user