-
Notifications
You must be signed in to change notification settings - Fork 140
CBG-4280 consolidate Attachment on document #7647
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
Conversation
- merge Document.SyncData.Attachments, Document.GlobalSyncData.GlobalAttachments, and Document.DocAttachments into Document.Attachments - Document.SyncData.Attachments becomes Document.SyncData.AttachmentsPre4dot0 and is used for unmarshalling, but should be cleared before writing a document - rename GlobalSyncData.GlobalAttachments to allow referring to Document.Attachments as GlobalSyncData is an embedded struct in Document
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request consolidates attachment metadata storage in Sync Gateway documents by merging three separate attachment storage locations into a single unified location.
- Merges
Document.SyncData.Attachments
,Document.GlobalSyncData.GlobalAttachments
, andDocument.DocAttachments
intoDocument._globalSync.Attachments
- Introduces
Document.SyncData.AttachmentsPre4dot0
for backward compatibility during unmarshalling - Provides getter/setter methods (
Attachments()
andSetAttachments()
) for cleaner access to attachment metadata
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
db/document.go | Core attachment consolidation logic with new unified storage and access methods |
db/crud.go | Updates document operations to use new attachment accessor methods |
db/blip_handler.go | Updates BLIP protocol handling to use new attachment methods |
db/import.go | Updates import functionality to use new attachment methods |
db/attachment.go | Updates attachment storage to use new accessor methods |
Multiple test files | Updates test assertions to use new attachment accessor methods |
Comments suppressed due to low confidence (1)
rest/attachment_test.go:2837
- The test configuration change from
nil
to&RestTesterConfig{AutoImport: base.Ptr(false)}
modifies test behavior significantly. Ensure this change is intentional and doesn't affect the test's validity.
rt := NewRestTester(t, &RestTesterConfig{AutoImport: base.Ptr(false)})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just couple of nit pick comments
CBG-4280 consolidate Attachment on document
Document.SyncData.Attachments
,Document.GlobalSyncData.GlobalAttachments
, andDocument.DocAttachments
intoDocument._globalSync.Attachments
Document.SyncData.Attachments
becomesDocument.SyncData.AttachmentsPre4dot0
and is used for unmarshalling, but should be cleared before writing a documentGlobalSyncData.GlobalAttachments
toGlobalSyncData.Attachments
I feel pretty comfortable with the amount of testing that this has, especially after I did 7ded498
I've considered whether to make
GlobalSyncData
not embedded intoDocument
, but ultimately I decided not to for the ease of referring toDocument.Attachments
in the code. This makes the in memory data structure sThings I don't love:
Document.SyncData.AttachmentsPre4dot0
has to exist to unmarshal SyncData, but we need to be sure to clear this when we are writing this data. This is handled inunmarshalDocumentWithXattrs
. An alternate approach to what I did would be to create aMarshalJSON
function to make sure that this field never got marshalled, but I couldn't think of a good way to do this.Document.MarshalJSON
has to re-add attachments into SyncData into order to haveImportDoc
work correctly. This is already noted as weird in this TODOsync_gateway/db/import.go
Line 78 in feebe5a
ImportDoc
because you almost never want to marshal metadata into an inline body. I think this hack inDocument.MarshalJSON
could be removed ifImportDoc
got refactored. SeeTestLegacyAttachmentMigrationToGlobal
for the only code that tests this pathway.Pre-review checklist
fmt.Print
,log.Print
, ...)base.UD(docID)
,base.MD(dbName)
)docs/api
Integration Tests
GSI=true,xattrs=true
https://jenkins.sgwdev.com/job/SyncGateway-Integration/3227/