Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
fix(daemon): publish merge instead of draft.
Browse files Browse the repository at this point in the history
  • Loading branch information
juligasa committed May 21, 2024
1 parent dfe61d0 commit 7784093
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
20 changes: 17 additions & 3 deletions backend/daemon/api/documents/v1alpha/documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ func (api *Server) ListAccountPublications(ctx context.Context, in *documents.Li
}

// MergeChanges implements the corresponding gRPC method. It merges changes and publishes them.
func (api *Server) MergeChanges(ctx context.Context, in *documents.MergeChangesRequest) (*documents.Document, error) {
func (api *Server) MergeChanges(ctx context.Context, in *documents.MergeChangesRequest) (*documents.Publication, error) {
me, err := api.getMe()
if err != nil {
return nil, err
Expand Down Expand Up @@ -990,13 +990,27 @@ func (api *Server) MergeChanges(ctx context.Context, in *documents.MergeChangesR
return nil, err
}

if err := api.blobs.SaveDraftBlob(ctx, entity.ID(), hb); err != nil {
if err := api.blobs.SaveBlob(ctx, hb); err != nil {
return nil, err
}

return api.GetDraft(ctx, &documents.GetDraftRequest{
oid, err := api.blobs.PublishBlob(ctx, hb.CID)
if err != nil {
return nil, err
}

if api.disc != nil {
if err := api.disc.ProvideCID(oid); err != nil {
return nil, err
}
}

return api.GetPublication(ctx, &documents.GetPublicationRequest{
DocumentId: entity.ID().String(),
Version: hb.CID.String(),
LocalOnly: true,
})

}

func (api *Server) getMe() (core.Identity, error) {
Expand Down
4 changes: 2 additions & 2 deletions backend/daemon/daemon_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ func TestMergeE2E(t *testing.T) {
Versions: []string{secondVersion.Version, forkedVersion.Version},
})
require.NoError(t, err)
require.Contains(t, mergedPub.PreviousVersion, secondVersion.Version)
require.Contains(t, mergedPub.PreviousVersion, forkedVersion.Version)
require.Contains(t, mergedPub.Document.PreviousVersion, secondVersion.Version)
require.Contains(t, mergedPub.Document.PreviousVersion, forkedVersion.Version)
}

func TestAPIGetRemotePublication(t *testing.T) {
Expand Down
39 changes: 39 additions & 0 deletions backend/hyper/hyper.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,45 @@ func (bs *Storage) GetDraft(ctx context.Context, eid EntityID) (ch Change, err e
return ch, nil
}

// PublishBlob publishes a blob.
func (bs *Storage) PublishBlob(ctx context.Context, c cid.Cid) (cid.Cid, error) {
conn, release, err := bs.db.Conn(ctx)
if err != nil {
return cid.Undef, err
}
defer release()

var out cid.Cid
if err := sqlitex.WithTx(conn, func() error {
newID, err := allocateBlobID(conn)
if err != nil {
return err
}

res, err := hypersql.BlobsGet(conn, c.Hash())
if err != nil {
return err
}

if err := sqlitex.Exec(conn, qBlobsTouch(), nil, newID, res.BlobsID); err != nil {
return err
}

out = cid.NewCidV1(uint64(res.BlobsCodec), res.BlobsMultihash)

return nil
}); err != nil {
return cid.Undef, err
}

if !out.Defined() {
return cid.Undef, fmt.Errorf("BUG: got draft without CID")
}

return out, nil
}

// PublishDraft publishes a draft.
func (bs *Storage) PublishDraft(ctx context.Context, eid EntityID) (cid.Cid, error) {
conn, release, err := bs.db.Conn(ctx)
if err != nil {
Expand Down

0 comments on commit 7784093

Please sign in to comment.