Skip to content
Open
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
3 changes: 2 additions & 1 deletion .idea/vcs.xml

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

2 changes: 2 additions & 0 deletions core/anytype/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"github.com/anyproto/anytype-heart/core/block/detailservice"
"github.com/anyproto/anytype-heart/core/block/editor"
"github.com/anyproto/anytype-heart/core/block/editor/converter"
"github.com/anyproto/anytype-heart/core/block/editor/widgetmigration"
"github.com/anyproto/anytype-heart/core/block/export"
importer "github.com/anyproto/anytype-heart/core/block/import"
"github.com/anyproto/anytype-heart/core/block/object/idderiver/idderiverimpl"
Expand Down Expand Up @@ -334,6 +335,7 @@ func Bootstrap(a *app.App, components ...app.Component) {
Register(api.New()).
Register(pushclient.New()).
Register(pushnotification.New()).
Register(widgetmigration.New()).
Register(durability.New()) // leave it the last one
}

Expand Down
18 changes: 9 additions & 9 deletions core/block/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ func (s *Service) DeleteObjectByFullID(id domain.FullID) error {
return err
}

entry, err := spc.Storage().HeadStorage().GetEntry(s.componentCtx, id.ObjectID)
if err != nil {
return fmt.Errorf("get head entry: %w", err)
}
// entry, err := spc.Storage().HeadStorage().GetEntry(s.componentCtx, id.ObjectID)
// if err != nil {
// return fmt.Errorf("get head entry: %w", err)
// }

switch sbType {
case coresb.SmartBlockTypeObjectType,
Expand All @@ -56,11 +56,11 @@ func (s *Service) DeleteObjectByFullID(id domain.FullID) error {
}
err = spc.DeleteTree(context.Background(), id.ObjectID)
default:
if entry.IsDerived {
err = s.deleteDerivedObject(id, sbType, spc)
} else {
err = spc.DeleteTree(context.Background(), id.ObjectID)
}
// if entry.IsDerived {
// err = s.deleteDerivedObject(id, sbType, spc)
// } else {
err = spc.DeleteTree(context.Background(), id.ObjectID)
// }
}
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions core/block/editor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type ObjectFactory struct {
statService debugstat.StatService
backlinksUpdater backlinks.UpdateWatcher
formatFetcher relationutils.RelationFormatFetcher
fixer fixer
}

func NewObjectFactory() *ObjectFactory {
Expand Down Expand Up @@ -129,6 +130,7 @@ func (f *ObjectFactory) Init(a *app.App) (err error) {
f.statService = debugstat.NewNoOp()
}
f.formatFetcher = app.MustComponent[relationutils.RelationFormatFetcher](a)
f.fixer = app.MustComponent[fixer](a)
return nil
}

Expand Down
1 change: 1 addition & 0 deletions core/block/editor/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ func (p *Page) CreationStateMigration(ctx *smartblock.InitContext) migration.Mig
case model.ObjectType_collection:
blockContent := template.MakeDataviewContent(true, nil, nil, nil)
templates = append(templates,
template.WithTitle,
template.WithDataview(blockContent, false),
)
default:
Expand Down
14 changes: 14 additions & 0 deletions core/block/editor/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ type WidgetObject struct {
basic.Updatable
widget.Widget
basic.DetailsSettable

fixer fixer
}

type fixer interface {
DeleteGarbage(spaceId string) error
}

func (f *ObjectFactory) newWidgetObject(
Expand All @@ -42,6 +48,7 @@ func (f *ObjectFactory) newWidgetObject(
DetailsSettable: bs,
IHistory: basic.NewHistory(sb),
Widget: widget.NewWidget(sb),
fixer: f.fixer,
}
}

Expand Down Expand Up @@ -87,6 +94,13 @@ func (w *WidgetObject) Init(ctx *smartblock.InitContext) (err error) {
ctx.State.Unlink(id)
}

go func() {
derr := w.fixer.DeleteGarbage(w.SpaceID())
if derr != nil {
log.Errorf("widget: delete garbage: %v", derr)
}
}()

return nil
}

Expand Down
131 changes: 131 additions & 0 deletions core/block/editor/widgetmigration/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package widgetmigration

import (
"context"
"fmt"

"github.com/anyproto/any-sync/app"

"github.com/anyproto/anytype-heart/core/block/cache"
"github.com/anyproto/anytype-heart/core/block/editor/smartblock"
"github.com/anyproto/anytype-heart/core/block/object/objectcreator"
"github.com/anyproto/anytype-heart/core/domain"
coresb "github.com/anyproto/anytype-heart/pkg/lib/core/smartblock"
"github.com/anyproto/anytype-heart/pkg/lib/localstore/objectstore"
"github.com/anyproto/anytype-heart/pkg/lib/logging"
"github.com/anyproto/anytype-heart/space"
)

const CName = "core.block.editor.widgetmigration"

const internalKeyRecentlyEdited = "recently_edited"
const internalKeyRecentlyOpened = "recently_opened"
const internalKeyOldPinned = "old_pinned"

var log = logging.Logger(CName)

Check failure on line 25 in core/block/editor/widgetmigration/service.go

View workflow job for this annotation

GitHub Actions / lint

var log is unused (unused)

type Service interface {
app.ComponentRunnable

MigrateWidgets(objectId string) error
AddToOldPinnedCollection(space smartblock.Space, favoriteIds []string) error
DeleteGarbage(spaceId string) error
}

type deleter interface {
DeleteObjectByFullID(id domain.FullID) error
}

type service struct {
componentCtx context.Context
componentCtxCancel context.CancelFunc

objectGetter cache.ObjectGetter

Check failure on line 43 in core/block/editor/widgetmigration/service.go

View workflow job for this annotation

GitHub Actions / lint

field objectGetter is unused (unused)
objectCreator objectcreator.Service

Check failure on line 44 in core/block/editor/widgetmigration/service.go

View workflow job for this annotation

GitHub Actions / lint

field objectCreator is unused (unused)
spaceService space.Service
objectStore objectstore.ObjectStore

Check failure on line 46 in core/block/editor/widgetmigration/service.go

View workflow job for this annotation

GitHub Actions / lint

field objectStore is unused (unused)
deleter deleter
}

func New() Service {
return &service{}

}

func (s *service) Name() string {
return CName
}

func (s *service) Run(ctx context.Context) error {
return nil
}

func (s *service) Close(ctx context.Context) error {
if s.componentCtxCancel != nil {
s.componentCtxCancel()
}
return nil
}

func (s *service) Init(a *app.App) error {
s.componentCtx, s.componentCtxCancel = context.WithCancel(context.Background())

s.objectGetter = app.MustComponent[cache.ObjectGetter](a)
s.objectCreator = app.MustComponent[objectcreator.Service](a)
s.spaceService = app.MustComponent[space.Service](a)
s.objectStore = app.MustComponent[objectstore.ObjectStore](a)
s.deleter = app.MustComponent[deleter](a)
return nil
}

func (s *service) DeleteGarbage(spaceId string) error {
spc, err := s.spaceService.Get(s.componentCtx, spaceId)
if err != nil {
return fmt.Errorf("get space: %w", err)
}

for _, cs := range []struct {
uk domain.UniqueKey
}{
{
uk: domain.MustUniqueKey(coresb.SmartBlockTypePage, internalKeyOldPinned),
},
{
uk: domain.MustUniqueKey(coresb.SmartBlockTypePage, internalKeyRecentlyOpened),
},
{
uk: domain.MustUniqueKey(coresb.SmartBlockTypePage, internalKeyRecentlyEdited),
},
} {
go func() {
id, err := spc.DeriveObjectID(s.componentCtx, cs.uk)
if err != nil {
fmt.Println("DERIVE OBJECT ID", err)
return
}

err = s.deleter.DeleteObjectByFullID(domain.FullID{
ObjectID: id,
SpaceID: spaceId,
})
if err != nil {
fmt.Println("DELETE OBJECT", err)
return
}
fmt.Println("DELETED", id, cs.uk.InternalKey(), id)
}()
}
return nil
}

func (s *service) MigrateWidgets(objectId string) error {
return nil
}

func (s *service) AddToOldPinnedCollection(space smartblock.Space, favoriteIds []string) error {
return nil
}

func (s *service) addToMigratedCollection(space smartblock.Space, collId string, favoriteIds []string) error {

Check failure on line 129 in core/block/editor/widgetmigration/service.go

View workflow job for this annotation

GitHub Actions / lint

func (*service).addToMigratedCollection is unused (unused)
return nil
}
Loading
Loading