Skip to content

Commit 3c4eb74

Browse files
addressed cursor comments
1 parent 3a61ef3 commit 3c4eb74

File tree

3 files changed

+17
-30
lines changed

3 files changed

+17
-30
lines changed

v2/arangodb/collection_documents_create_impl.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"context"
2525
"io"
2626
"net/http"
27+
"reflect"
2728

2829
"github.com/pkg/errors"
2930

@@ -177,12 +178,18 @@ func (c *collectionDocumentCreateResponseReader) Read() (CollectionDocumentCreat
177178
var meta CollectionDocumentCreateResponse
178179

179180
if c.options != nil {
180-
meta.Old = c.options.OldObject
181-
meta.New = c.options.NewObject
181+
if c.options.OldObject != nil {
182+
meta.Old = reflect.New(reflect.TypeOf(c.options.OldObject).Elem()).Interface()
183+
}
184+
if c.options.NewObject != nil {
185+
meta.New = reflect.New(reflect.TypeOf(c.options.NewObject).Elem()).Interface()
186+
}
182187
}
183188

184189
c.response.DocumentMeta = &meta.DocumentMeta
185190
c.response.ResponseStruct = &meta.ResponseStruct
191+
c.response.Old = newUnmarshalInto(meta.Old)
192+
c.response.New = newUnmarshalInto(meta.New)
186193

187194
if err := c.array.Unmarshal(&c.response); err != nil {
188195
if err == io.EOF {
@@ -191,12 +198,6 @@ func (c *collectionDocumentCreateResponseReader) Read() (CollectionDocumentCreat
191198
return CollectionDocumentCreateResponse{}, err
192199
}
193200

194-
// Update meta with the unmarshaled data
195-
meta.DocumentMeta = *c.response.DocumentMeta
196-
meta.ResponseStruct = *c.response.ResponseStruct
197-
meta.Old = c.response.Old
198-
meta.New = c.response.New
199-
200201
if meta.Error != nil && *meta.Error {
201202
return meta, meta.AsArangoError()
202203
}

v2/arangodb/collection_documents_replace_impl.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,18 @@ func (c *collectionDocumentReplaceResponseReader) Read() (CollectionDocumentRepl
177177
var meta CollectionDocumentReplaceResponse
178178

179179
if c.options != nil {
180-
// Create new instances for each document to avoid reusing the same pointers
181180
if c.options.OldObject != nil {
182-
oldObjectType := reflect.TypeOf(c.options.OldObject).Elem()
183-
meta.Old = reflect.New(oldObjectType).Interface()
181+
meta.Old = reflect.New(reflect.TypeOf(c.options.OldObject).Elem()).Interface()
184182
}
185183
if c.options.NewObject != nil {
186-
newObjectType := reflect.TypeOf(c.options.NewObject).Elem()
187-
meta.New = reflect.New(newObjectType).Interface()
184+
meta.New = reflect.New(reflect.TypeOf(c.options.NewObject).Elem()).Interface()
188185
}
189186
}
190187

191188
c.response.DocumentMetaWithOldRev = &meta.DocumentMetaWithOldRev
192189
c.response.ResponseStruct = &meta.ResponseStruct
190+
c.response.Old = newUnmarshalInto(meta.Old)
191+
c.response.New = newUnmarshalInto(meta.New)
193192

194193
if err := c.array.Unmarshal(&c.response); err != nil {
195194
if err == io.EOF {
@@ -198,12 +197,6 @@ func (c *collectionDocumentReplaceResponseReader) Read() (CollectionDocumentRepl
198197
return CollectionDocumentReplaceResponse{}, err
199198
}
200199

201-
// Update meta with the unmarshaled data
202-
meta.DocumentMetaWithOldRev = *c.response.DocumentMetaWithOldRev
203-
meta.ResponseStruct = *c.response.ResponseStruct
204-
meta.Old = c.response.Old
205-
meta.New = c.response.New
206-
207200
if meta.Error != nil && *meta.Error {
208201
return meta, meta.AsArangoError()
209202
}

v2/arangodb/collection_documents_update_impl.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,18 @@ func (c *collectionDocumentUpdateResponseReader) Read() (CollectionDocumentUpdat
177177
var meta CollectionDocumentUpdateResponse
178178

179179
if c.options != nil {
180-
// Create new instances for each document to avoid reusing the same pointers
181180
if c.options.OldObject != nil {
182-
oldObjectType := reflect.TypeOf(c.options.OldObject).Elem()
183-
meta.Old = reflect.New(oldObjectType).Interface()
181+
meta.Old = reflect.New(reflect.TypeOf(c.options.OldObject).Elem()).Interface()
184182
}
185183
if c.options.NewObject != nil {
186-
newObjectType := reflect.TypeOf(c.options.NewObject).Elem()
187-
meta.New = reflect.New(newObjectType).Interface()
184+
meta.New = reflect.New(reflect.TypeOf(c.options.NewObject).Elem()).Interface()
188185
}
189186
}
190187

191188
c.response.DocumentMetaWithOldRev = &meta.DocumentMetaWithOldRev
192189
c.response.ResponseStruct = &meta.ResponseStruct
190+
c.response.Old = newUnmarshalInto(meta.Old)
191+
c.response.New = newUnmarshalInto(meta.New)
193192

194193
if err := c.array.Unmarshal(&c.response); err != nil {
195194
if err == io.EOF {
@@ -198,12 +197,6 @@ func (c *collectionDocumentUpdateResponseReader) Read() (CollectionDocumentUpdat
198197
return CollectionDocumentUpdateResponse{}, err
199198
}
200199

201-
// Update meta with the unmarshaled data
202-
meta.DocumentMetaWithOldRev = *c.response.DocumentMetaWithOldRev
203-
meta.ResponseStruct = *c.response.ResponseStruct
204-
meta.Old = c.response.Old
205-
meta.New = c.response.New
206-
207200
if meta.Error != nil && *meta.Error {
208201
return meta, meta.AsArangoError()
209202
}

0 commit comments

Comments
 (0)