MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / Purge

Method Purge

db/crud.go:3213–3263  ·  view source on GitHub ↗

Purges a document from the bucket (no tombstone)

(ctx context.Context, key string, needsAudit bool)

Source from the content-addressed store, hash-verified

3211
3212// Purges a document from the bucket (no tombstone)
3213func (db *DatabaseCollectionWithUser) Purge(ctx context.Context, key string, needsAudit bool) error {
3214 doc, rawBucketDoc, err := db.GetDocumentWithRaw(ctx, key, DocUnmarshalAll)
3215 if err != nil {
3216 return err
3217 }
3218
3219 attachments, err := getAttachmentIDsForLeafRevisions(ctx, db, doc, "")
3220 if err != nil {
3221 return err
3222 }
3223
3224 for attachmentID, attachmentNames := range attachments {
3225 err = db.dataStore.Delete(attachmentID)
3226 if err != nil {
3227 base.WarnfCtx(ctx, "Unable to delete attachment %q. Error: %v", attachmentID, err)
3228 }
3229 for _, attachmentName := range attachmentNames {
3230 base.Audit(ctx, base.AuditIDAttachmentDelete, base.AuditFields{
3231 base.AuditFieldDocID: doc.ID,
3232 base.AuditFieldAttachmentID: attachmentName,
3233 })
3234 }
3235
3236 }
3237
3238 if db.UseXattrs() {
3239 // Clean up _sync and _globalSync (if present). Leave _vv and _mou since they are also shared by XDCR/Eventing.
3240 xattrsToDelete := []string{base.SyncXattrName, base.GlobalXattrName}
3241 // TODO: CBG-4796 - we currently need to determine a list of present xattrs before we delete to avoid differences
3242 // between Rosmar and Couchbase Server implementations of DeleteWithXattrs and GetWithXattrs.
3243 var presentXattrsToDelete []string
3244 if rawBucketDoc != nil && rawBucketDoc.Xattrs != nil {
3245 presentXattrsToDelete = base.KeysPresent(rawBucketDoc.Xattrs, xattrsToDelete)
3246 }
3247 if err := db.dataStore.DeleteWithXattrs(ctx, key, presentXattrsToDelete); err != nil {
3248 return err
3249 }
3250 } else {
3251 err := db.dataStore.Delete(key)
3252 if err != nil {
3253 return err
3254 }
3255 }
3256 if needsAudit {
3257 base.Audit(ctx, base.AuditIDDocumentDelete, base.AuditFields{
3258 base.AuditFieldDocID: key,
3259 base.AuditFieldPurged: true,
3260 })
3261 }
3262 return nil
3263}
3264
3265// ////// CHANNELS:
3266

Callers

nothing calls this directly

Calls 8

WarnfCtxFunction · 0.92
AuditFunction · 0.92
KeysPresentFunction · 0.92
GetDocumentWithRawMethod · 0.80
DeleteMethod · 0.45
UseXattrsMethod · 0.45
DeleteWithXattrsMethod · 0.45

Tested by

no test coverage detected