-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from anyproto/go-1561-usecase-design-fixes
GO-1561 Usecases | Design fixes
- Loading branch information
Showing
12 changed files
with
118 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package main | ||
|
||
import ( | ||
_ "embed" | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/anyproto/anytype-heart/pkg/lib/pb/model" | ||
) | ||
|
||
//go:embed excluded.json | ||
var excludedJson []byte | ||
|
||
const ( | ||
objectTypeIdPattern = "ot-" | ||
relationIdPattern = "rel-" | ||
) | ||
|
||
var ( | ||
objectsToExcludeSlice []string | ||
objectsToExclude map[string]struct{} | ||
|
||
shouldObjectTypesBeExcluded = false | ||
shouldRelationsBeExcluded = false | ||
|
||
sbTypesToBeExcluded = map[model.SmartBlockType]struct{}{ | ||
model.SmartBlockType_Workspace: {}, | ||
model.SmartBlockType_Widget: {}, | ||
model.SmartBlockType_ProfilePage: {}, | ||
model.SmartBlockType_Template: {}, | ||
} | ||
) | ||
|
||
func init() { | ||
err := json.Unmarshal(excludedJson, &objectsToExcludeSlice) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to unmarshal excluded.json: %v", err)) | ||
} | ||
objectsToExclude = make(map[string]struct{}) | ||
for _, id := range objectsToExcludeSlice { | ||
switch id { | ||
case objectTypeIdPattern: | ||
shouldObjectTypesBeExcluded = true | ||
case relationIdPattern: | ||
shouldRelationsBeExcluded = true | ||
default: | ||
objectsToExclude[id] = struct{}{} | ||
} | ||
} | ||
} | ||
|
||
func shouldBeExcluded(id string, sbType model.SmartBlockType) bool { | ||
if _, found := sbTypesToBeExcluded[sbType]; found { | ||
fmt.Printf("Smartblock '%s' is excluded as has type %s\n", id, sbType.String()) | ||
return true | ||
} | ||
|
||
if shouldObjectTypesBeExcluded && strings.HasPrefix(id, objectTypeIdPattern) { | ||
fmt.Printf("Smartblock '%s' is excluded as it is object type\n", id) | ||
return true | ||
} | ||
|
||
if shouldRelationsBeExcluded && strings.HasPrefix(id, relationIdPattern) { | ||
fmt.Printf("Smartblock '%s' is excluded as it is relation\n", id) | ||
return true | ||
} | ||
|
||
if _, found := objectsToExclude[id]; found { | ||
fmt.Printf("Smartblock '%s' is excluded as it is listed in 'excluded.json'\n", id) | ||
return true | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[ | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.