Skip to content

Add Ml shared preferences for custom model storage #2104

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

Merged
merged 6 commits into from
Oct 29, 2020
Merged

Conversation

annzimmer
Copy link
Contributor

No description provided.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Oct 26, 2020

Coverage Report

Affected SDKs

  • firebase-ml-modeldownloader

    SDK overall coverage changed from 93.55% (844ff28) to 95.63% (b0e24228) by +2.08%.

    Filename Base (844ff28) Head (b0e24228) Diff
    CustomModel.java 92.86% 89.29% -3.57%
    SharedPreferencesUtil.java ? 98.80% ?

Test Logs

Notes

HTML coverage reports can be produced locally with ./gradlew <product>:checkCoverage.
Report files are located at <product-build-dir>/reports/jacoco/.

Head commit (b0e24228) is created by Prow via merging commits: 844ff28 33eed38.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Oct 26, 2020

Binary Size Report

Affected SDKs

  • firebase-ml-modeldownloader

    Type Base (844ff28) Head (b0e24228) Diff
    aar 9.65 kB 12.6 kB +2.99 kB (+31.0%)
    apk (aggressive) 78.8 kB 78.8 kB +8 B (+0.0%)
    apk (release) 664 kB 666 kB +1.96 kB (+0.3%)

Test Logs

Notes

Head commit (b0e24228) is created by Prow via merging commits: 844ff28 33eed38.

@annzimmer
Copy link
Contributor Author

/retest

1 similar comment
@annzimmer
Copy link
Contributor Author

/retest

*/
public CustomModel(
@NonNull String name, long downloadId, long fileSize, @NonNull String modelHash) {
this.modelHash = modelHash;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could call the other constructor from here and assignments centralized in a single method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@@ -76,18 +118,31 @@ public long getDownloadId() {
return downloadId;
}

@Override
public boolean equals(Object o) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Override hashCode when overriding equals (Item 11 in Effective Java)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks - added.

* model is present - this returns the details of that model, including local file path. If an
* update of an existing model is in progress, the local model plus the download id for the new
* upload is returned. To get only details related to the downloading model use
* getDownloadingCustomModelDetails. If this is the initial download of a local file - the
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* getDownloadingCustomModelDetails. If this is the initial download of a local file - the
* {@link #getDownloadingCustomModelDetails}. If this is the initial download of a local file - the

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

private static final CustomModel CUSTOM_MODEL_DOWNLOADING =
new CustomModel(MODEL_NAME, 986, 100, MODEL_HASH);

// private static final FirebaseApp FIREBASE_APP = FirebaseApp.initializeApp(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this code be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

String.format(LOCAL_MODEL_FILE_PATH_PATTERN, persistenceKey, modelName), filePath)
.apply();

clearDownloadingModelDetails(customModel.getName());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be useful to do the clearing as part of the change above? If yes, then you can pass the editor to clearDownloadingModelDetails and use it to add the remove statements in a single apply() call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great idea.

.putLong(
String.format(DOWNLOAD_BEGIN_TIME_MS_PATTERN, persistenceKey, modelName),
SystemClock.elapsedRealtime())
.apply();
Copy link
Collaborator

Choose a reason for hiding this comment

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

apply() only alters the in-memory contents of the SharedPreferences, and eventually writes to disk, which may fail silently, unlike commit() that's synchronous. Just want to double check that this is an acceptable situation in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to commit

@annzimmer annzimmer merged commit 4285659 into master Oct 29, 2020
@annzimmer annzimmer deleted the mlStorage branch October 29, 2020 13:34
@firebase firebase locked and limited conversation to collaborators Nov 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes Override cla size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants