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

fix(web,server,worker): resolve threads bug in copier #1367

Merged
merged 4 commits into from
Jan 21, 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
2 changes: 1 addition & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
github.com/k0kubun/pp/v3 v3.3.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/labstack/echo/v4 v4.12.0
github.com/labstack/gommon v0.4.2
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1
github.com/oapi-codegen/runtime v1.1.1
github.com/paulmach/go.geojson v1.5.0
Expand Down Expand Up @@ -116,7 +117,6 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/jpillora/opts v1.2.3 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/maruel/panicparse/v2 v2.3.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down
28 changes: 6 additions & 22 deletions server/internal/adapter/gql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions server/internal/adapter/gql/gqlmodel/convert_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ func ToItem(vi item.Versioned, s *schema.Schema, gsList schema.List) *Item {
for _, s2 := range gsList {
groupFields = append(groupFields, toItemFields(i.Fields(), s2, true)...)
}
return &Item{
itm := Item{
ID: IDFrom(i.ID()),
ProjectID: IDFrom(i.Project()),
SchemaID: IDFrom(i.Schema()),
ModelID: IDFrom(i.Model()),
UserID: IDFromRef(i.User()),
IntegrationID: IDFromRef(i.Integration()),
ThreadID: IDFrom(i.Thread()),
MetadataID: IDFromRef(i.MetadataItem()),
IsMetadata: i.IsMetadata(),
OriginalID: IDFromRef(i.MetadataItem()),
Expand All @@ -39,6 +38,10 @@ func ToItem(vi item.Versioned, s *schema.Schema, gsList schema.List) *Item {
Version: vi.Version().String(),
Title: i.GetTitle(s),
}
if !i.Thread().Ref().IsNil() {
itm.ThreadID = IDFromRef(i.Thread().Ref())
}
return &itm
}
func toItemFields(fields item.Fields, s *schema.Schema, isGroupSchema bool) []*ItemField {
var res []*ItemField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestToItem(t *testing.T) {
ProjectID: IDFrom(pid),
ModelID: IDFrom(mid),
SchemaID: IDFrom(sid),
ThreadID: IDFrom(tid),
ThreadID: IDFromRef(tid.Ref()),
UserID: IDFromRef(uid.Ref()),
IntegrationID: IDFromRef(nid.Ref()),
nourbalaha marked this conversation as resolved.
Show resolved Hide resolved
CreatedAt: i.ID().Timestamp(),
Expand Down
4 changes: 2 additions & 2 deletions server/internal/adapter/gql/gqlmodel/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion server/internal/adapter/gql/resolver_item.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 14 additions & 9 deletions server/internal/infrastructure/mongo/mongodoc/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ func NewVersionedItemConsumer() *VersionedItemConsumer {

func NewItem(i *item.Item) (*ItemDocument, string) {
itmId := i.ID().String()
return &ItemDocument{
d := ItemDocument{
ID: itmId,
Schema: i.Schema().String(),
ModelID: i.Model().String(),
Project: i.Project().String(),
Thread: i.Thread().String(),
MetadataItem: i.MetadataItem().StringRef(),
OriginalItem: i.OriginalItem().StringRef(),
Fields: lo.FilterMap(i.Fields(), func(f *item.Field, _ int) (ItemFieldDocument, bool) {
Expand All @@ -89,7 +88,11 @@ func NewItem(i *item.Item) (*ItemDocument, string) {
Integration: i.Integration().StringRef(),
Assets: i.AssetIDs().Strings(),
IsMetadata: i.IsMetadata(),
}, itmId
}
if !i.Thread().IsEmpty() {
d.Thread = i.Thread().String()
}
return &d, itmId
}

func (d *ItemDocument) Model() (*item.Item, error) {
Expand All @@ -113,11 +116,6 @@ func (d *ItemDocument) Model() (*item.Item, error) {
return nil, err
}

tid, err := id.ThreadIDFrom(d.Thread)
if err != nil {
return nil, err
}

fields, err := util.TryMap(d.Fields, func(f ItemFieldDocument) (*item.Field, error) {
// compat
if f.Field != "" {
Expand Down Expand Up @@ -152,11 +150,18 @@ func (d *ItemDocument) Model() (*item.Item, error) {
Model(mid).
MetadataItem(id.ItemIDFromRef(d.MetadataItem)).
OriginalItem(id.ItemIDFromRef(d.OriginalItem)).
Thread(tid).
IsMetadata(d.IsMetadata).
Fields(fields).
Timestamp(d.Timestamp)

if d.Thread != "" {
tid, err := id.ThreadIDFrom(d.Thread)
if err != nil {
return nil, err
}
ib.Thread(tid)
}

if uId := accountdomain.UserIDFromRef(d.User); uId != nil {
ib = ib.User(*uId)
}
Expand Down
4 changes: 4 additions & 0 deletions server/internal/usecase/interactor/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ func (i Model) copyItems(ctx context.Context, oldSchemaID, newSchemaID id.Schema
Type: task.ChangeTypeULID,
Value: timestamp.UnixMilli(),
},
"thread": {
Type: task.ChangeTypeSet,
Value: nil,
},
"__r": { // tag
Type: task.ChangeTypeSet,
Value: []string{"latest"},
Expand Down
6 changes: 3 additions & 3 deletions server/pkg/item/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func (b *Builder) Build() (*Item, error) {
if b.i.model.IsNil() {
return nil, ErrInvalidID
}
if b.i.thread.IsNil() {
return nil, ErrInvalidID
}
// if b.i.thread.IsNil() {
// return nil, ErrInvalidID
// }
nourbalaha marked this conversation as resolved.
Show resolved Hide resolved
if b.i.timestamp.IsZero() {
b.i.timestamp = util.Now()
}
Expand Down
26 changes: 13 additions & 13 deletions server/pkg/item/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,19 @@ func TestBuilder_Build(t *testing.T) {
want: nil,
wantErr: id.ErrInvalidID,
},
{
name: "should fail: invalid thread ID",
fields: fields{
i: &Item{
id: iid,
schema: sid,
project: pid,
model: mid,
},
},
want: nil,
wantErr: id.ErrInvalidID,
},
// {
// name: "should fail: invalid thread ID",
// fields: fields{
// i: &Item{
// id: iid,
// schema: sid,
// project: pid,
// model: mid,
// },
// },
// want: nil,
// wantErr: id.ErrInvalidID,
// },
}

for _, tt := range tests {
Expand Down
4 changes: 2 additions & 2 deletions server/schemas/item.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type Item implements Node {
id: ID!
schemaId: ID!
threadId: ID!
threadId: ID
modelId: ID!
projectId: ID!
integrationId: ID
Expand All @@ -16,7 +16,7 @@ type Item implements Node {
model: Model!
status: ItemStatus!
project: Project!
thread: Thread!
thread: Thread
fields: [ItemField!]!
assets: [Asset]!
referencedItems:[Item!]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export default () => {
createdBy: { id: item.createdBy?.id ?? "", name: item.createdBy?.name ?? "" },
updatedBy: item.updatedBy?.name ?? "",
fields: fieldsGet(item as unknown as Item),
comments: item.thread.comments.map(comment =>
comments: item.thread?.comments.map(comment =>
fromGraphQLComment(comment as GQLComment),
),
version: item.version,
Expand Down
3 changes: 2 additions & 1 deletion worker/internal/infrastructure/mongo/copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mongo
import (
"context"
"errors"
"strings"

"github.com/google/uuid"
"github.com/oklog/ulid"
Expand Down Expand Up @@ -97,7 +98,7 @@ func (r *Copier) Copy(ctx context.Context, f bson.M, changesMap task.Changes) er
if err != nil {
return rerror.ErrInternalBy(err)
}
result[k] = newId.String()
result[k] = strings.ToLower(newId.String())
case task.ChangeTypeSet:
result[k] = change.Value
}
Expand Down
Loading