Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(server): add logs to item import cmd #1381

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion server/cmd/reearth-cms/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func main() {
log.Fatalf("asset not found: %v", err)
}

log.Infof("importing items from asset %s", aId.String())

items, fields, err := itemsFromJson(frc, *format == "geojson", geometryFieldKey, *sp)
if err != nil {
log.Fatalf("failed to parse json: %v", err)
Expand Down Expand Up @@ -164,7 +166,7 @@ func itemsFromJson(r io.Reader, isGeoJson bool, geoField *string, sp schema.Pack

items := make([]interfaces.ImportItemParam, 0)
fields := make([]interfaces.CreateFieldParam, 0)
for _, o := range jsonObjects {
for i, o := range jsonObjects {
var iId *id.ItemID
//idStr, _ := o["id"].(string)
//iId = id.ItemIDFromRef(&idStr)
Expand Down Expand Up @@ -251,7 +253,12 @@ func itemsFromJson(r io.Reader, isGeoJson bool, geoField *string, sp schema.Pack
})
}
items = append(items, item)
if i > 0 && i%1000 == 0 {
log.Infof("%d items prepared...", i)
}
}
log.Infof("%d items prepared.", len(items))
log.Infof("items preparation done.")
return items, fields, nil
}

Expand Down
12 changes: 10 additions & 2 deletions server/internal/usecase/interactor/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,12 @@ func (i Item) Import(ctx context.Context, param interfaces.ImportItemsParam, ope
if err != nil {
return interfaces.ImportItemsResponse{}, err
}
log.Infof("schema %s updated, %v new field created.", s.ID(), len(param.Fields))
}

f := func(ctx context.Context) (interfaces.ImportItemsResponse, error) {

for _, itemParam := range param.Items {
for j, itemParam := range param.Items {

var oldItem *item.Item
if itemParam.ItemId != nil {
Expand Down Expand Up @@ -586,15 +587,22 @@ func (i Item) Import(ctx context.Context, param interfaces.ImportItemsParam, ope
} else {
res.ItemUpdated()
}

if j > 0 && j%1000 == 0 {
log.Infof(" %d items created...", j)
}
}
log.Infof(" %d items created.", len(param.Items))

if err := i.repos.Thread.SaveAll(ctx, threadsToSave); err != nil {
return interfaces.ImportItemsResponse{}, err
}
log.Infof(" %d threads saved.", len(threadsToSave))

if err := i.repos.Item.SaveAll(ctx, itemsToSave); err != nil {
return interfaces.ImportItemsResponse{}, err
}
log.Infof(" %d items saved.", len(itemsToSave))

return res.Into(), nil
}
Expand Down Expand Up @@ -675,7 +683,7 @@ func (i Item) Import2(ctx context.Context, aId id.AssetID, mId id.ModelID, forma
}

if err := i.gateways.TaskRunner.Run(ctx, taskPayload.Payload()); err != nil {
return fmt.Errorf("failed to trigger copy event: %w", err)
return fmt.Errorf("failed to trigger import event: %w", err)
}

log.Info("item: successfully triggered import event")
Expand Down