Skip to content
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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

KirillSto
Copy link
Member

@KirillSto KirillSto commented Sep 2, 2024

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

  • Introduce gallery.Service, where all logic with import of gallery usecases is accumulated
  • Introduce IndexCache that saves latest index locally
  • Introduce DashboardInjector that injects Homepage object during ooooold space migration
  • Import built-in usecases using experience pipeline (it is possible due to widget and workspace being added to archives)
  • Add cache parameter to all gallery-related RPCs
  • Experience import uses clientCache in case built-in archive could not be downloaded from remote
  • Renewed Get Started usecase (Welcome letter)
  • Slight changes on Usecase validator

@KirillSto KirillSto self-assigned this Sep 2, 2024
@KirillSto KirillSto marked this pull request as ready for review September 24, 2024 11:29
@KirillSto KirillSto changed the title GO-3946 Gallery cache GO-3946 | GO-3587 - Gallery cache Sep 24, 2024
Copy link

github-actions bot commented Sep 24, 2024

New Coverage 47.9% of statements
Patch Coverage 61.5% of changed statements (273/444)

Coverage provided by https://github.com/seriousben/go-patch-cover-action

@@ -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)

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?

Copy link
Member Author

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()

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?

Copy link
Member Author

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 😄

}

if errors.Is(err, ErrNotModified) {
manifest, err := getManifestByDownloadLink(localIndex, downloadLink)

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)?


if localIndex != nil {
log.Warn("failed to download index from remote. Returning local index", zap.Error(err))
manifest, err := getManifestByDownloadLink(localIndex, downloadLink)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same

}
}

info.Description = stripTags(info.Description)

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?🧐

Copy link
Member Author

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

return err
}

if rmErr := os.Remove(path); rmErr != nil {

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?

Copy link
Member Author

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

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?

Copy link
Member Author

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 🙈

}

if cachePath == "" {
if ctx == nil {

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?

Copy link
Member Author

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!


func getArchiveReaderAndSize(url string) (reader io.ReadCloser, size int64, err error) {
client := http.Client{Timeout: 15 * time.Second}
// nolint: gosec

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? 🧐

Copy link
Member Author

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 🙈

}

func generateMapOfDownloadLinksByNames(index *pb.RpcGalleryDownloadIndexResponse) map[string]string {
m := make(map[string]string)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preallocate

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

}
defer r.Close()

archives = make(map[string][]byte)

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@KirillSto KirillSto changed the title GO-3946 | GO-3587 - Gallery cache GO-3946 | GO-3587 | GO-4130 - Gallery cache Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants