-
Notifications
You must be signed in to change notification settings - Fork 47
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-3946 | GO-3587 | GO-4130 - Gallery cache #1531
base: main
Are you sure you want to change the base?
Conversation
Coverage provided by https://github.com/seriousben/go-patch-cover-action |
core/block/import/pb/converter.go
Outdated
@@ -163,7 +163,7 @@ func (p *Pb) handleImportPath( | |||
needToImportWidgets = p.needToImportWidgets(profile.Address, pr.AccountId) | |||
profileID = profile.ProfileId | |||
} | |||
return p.getSnapshotsFromProvidedFiles(pathCount, importSource, allErrors, path, profileID, needToImportWidgets, isMigration, importType) | |||
return p.getSnapshotsFromProvidedFiles(pathCount, importSource, allErrors, path, profileID, needToImportWidgets, isMigration, isNewSpace, importType) |
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 signature is very huge now, may be we can introduce some dataObject or request object with all following parameters?
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 refactored whole converter.go a little bit. Actaully, we can save a lot of info inside Pb struct state, so there is no need to transfer it throghout method calls. Please check if I could miss smth
} | ||
|
||
func (c *cache) GetManifest(downloadLink string, timeoutInSeconds int) (info *model.ManifestInfo, err error) { | ||
localIndex, err := c.storage.getIndex() |
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 extract some duplicate code from GetIndex and GetManifest? Looks like they have a lot of common code?
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, it hepled to remove 30 lines 😄
core/gallery/cache.go
Outdated
} | ||
|
||
if errors.Is(err, ErrNotModified) { | ||
manifest, err := getManifestByDownloadLink(localIndex, downloadLink) |
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 just return getManifestByDownloadLink(localIndex, downloadLink)
?
core/gallery/cache.go
Outdated
|
||
if localIndex != nil { | ||
log.Warn("failed to download index from remote. Returning local index", zap.Error(err)) | ||
manifest, err := getManifestByDownloadLink(localIndex, downloadLink) |
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
core/gallery/cache.go
Outdated
} | ||
} | ||
|
||
info.Description = stripTags(info.Description) |
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 think, it should be moved out of function, because it doesn't relate to validation, because according to name, this function is supposed to just validate manifest?🧐
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 changed strip logic a lil bit. Now it accepts manifest and is not sticked to validation
util/dashboardinjector/injector.go
Outdated
return err | ||
} | ||
|
||
if rmErr := os.Remove(path); rmErr != nil { |
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.
Should this logic also be executed in case of 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.
Yes, it should. In case we have run into some problem on import stage, we still need to remove temp file
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.
Then it should be in defer?
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, thank you! I put it into defer and also fixed error return. On import failure I used to return wrong error 🙈
core/gallery/service.go
Outdated
} | ||
|
||
if cachePath == "" { | ||
if ctx == nil { |
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 if ImportBuiltInUseCase
should be called with context.Background() instead of nil to avoid such check?
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, I have added ctx to all calls, thank you!
core/gallery/service.go
Outdated
|
||
func getArchiveReaderAndSize(url string) (reader io.ReadCloser, size int64, err error) { | ||
client := http.Client{Timeout: 15 * time.Second} | ||
// nolint: gosec |
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.
Why do we need this comment? It seems like there is no security issues? 🧐
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.
Actally there is. Linter worried about referencing some mal resources 🙈
core/gallery/service.go
Outdated
} | ||
|
||
func generateMapOfDownloadLinksByNames(index *pb.RpcGalleryDownloadIndexResponse) map[string]string { | ||
m := make(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.
Preallocate
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!
core/gallery/service.go
Outdated
} | ||
defer r.Close() | ||
|
||
archives = make(map[string][]byte) |
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.
Allocate it near usage please
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-3946/add-cache-for-index-and-for-usecase
https://linear.app/anytype/issue/GO-3587/add-cache-on-gallerydownloadindex
https://linear.app/anytype/issue/GO-4130/substitute-current-get-started-usecase-with-new-one