-
Notifications
You must be signed in to change notification settings - Fork 54
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
GO-3964 ListRelationsByValue RPC #1552
Conversation
Coverage provided by /~https://github.com/seriousben/go-patch-cover-action |
@@ -504,3 +504,41 @@ func (s *dsObjectStore) QueryByIDAndSubscribeForChanges(ids []string, sub databa | |||
s.addSubscriptionIfNotExists(sub) | |||
return | |||
} | |||
|
|||
func (s *dsObjectStore) QueryAndProcess(q database.Query, proc func(details *types.Struct)) error { |
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.
QueryIterate?
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.
Renamed!
core/block/relation.go
Outdated
@@ -56,3 +64,75 @@ func (s *Service) ObjectTypeRemoveRelations(ctx context.Context, objectTypeId st | |||
return b.Apply(st) | |||
}) | |||
} | |||
|
|||
func (s *Service) ListRelationsWithValue(spaceId string, value *types.Value) (keys []string, counters []int64, err error) { |
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.
is it time for relationService?
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.
Yes 😌
pkg/lib/localstore/addr/addr.go
Outdated
@@ -48,3 +48,10 @@ func ExtractVirtualSourceType(id string) (model.SmartBlockType, error) { | |||
func TimeToID(t time.Time) string { | |||
return DatePrefix + t.Format("2006-01-02") | |||
} | |||
|
|||
func DateIDToDayStart(id string) (time.Time, error) { |
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.
it shouldn't be here, it's pretty specific case, put it near usage
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.
Done!
} | ||
|
||
func (s *service) partitionObjectIDsBySpaceID(objectIDs []string) (map[string][]string, error) { | ||
res := map[string][]string{} |
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.
May be it can be preallocated?
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.
Done!
return fmt.Errorf("get space: %w", err) | ||
} | ||
return cache.Do(s, spc.DerivedIDs().Archive, func(b smartblock.SmartBlock) error { | ||
archive, ok := b.(collection.Collection) |
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.
Maybe extract to separate function?
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.
I have splitted this function onto two separate ones
return fmt.Errorf("unexpected archive block type: %T", b) | ||
} | ||
|
||
var multiErr multierror.Error |
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.
Can be combined
var (
multiErr multierror.Error.
anySucceed bool
)
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.
Thank you!
if err := multiErr.ErrorOrNil(); err != nil { | ||
log.Warn("failed to archive", zap.Error(err)) | ||
} | ||
if anySucceed { |
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.
It is seems like unnecessary check, because multiErr.ErrorOrNil() is nil for sure. So can we just return nil instead of lines 243-246?
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.
The point here is to return nil, if at least one object was processed without error.
If some objects were processed with error, than we should log it.
If all objects were processed with error, than we should return error.
So there is no issue here
if resultError != nil { | ||
log.Warn("failed to set objects as favorite", zap.Error(resultError)) | ||
} | ||
if anySucceed { |
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.
The same comment as for isArchive function
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.
Same situation is here
Condition: model.BlockContentDataviewFilter_Equal, | ||
Value: pbtypes.String(spaceId), | ||
}}}, func(details *types.Struct) { | ||
for key, v := range details.Fields { |
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.
Can we rename v to value or something? Because it looks like not consistent naming 🧐
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.
Yeah, fixed
if err != nil { | ||
return errors.Join(fmt.Errorf("iterate: %w", err), iter.Close()) | ||
} | ||
err = iter.Close() |
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.
Call "Close" in the defer, because it may cause a connection leak
iter, err := query.Iter(s.componentCtx)
if err != nil {
return fmt.Errorf("find: %w", err)
}
defer func() {
err = iter.Close()
}()
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.
Done!
https://linear.app/anytype/issue/GO-3964/provide-the-list-of-relations-on-the-layout-with-date-as-a-value