Closed Bug 1465380 Opened 6 years ago Closed 6 years ago

Add handling of objects and arrays to PlacesUtils.metadata, and add optional default values for get()

Categories

(Toolkit :: Places, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
mozilla62
Tracking Status
firefox62 --- fixed

People

(Reporter: standard8, Assigned: standard8)

References

Details

(Whiteboard: [fxsearch])

Attachments

(1 file)

As seen in bug 1460579, it would be helpful if we could automatically store objects and arrays in Places' metadata.

Additionally, it would be useful for the get() functions to take a default value to return should the item not exist in the database.
Comment on attachment 8981811 [details]
Bug 1465380 - Add handling of objects and arrays to PlacesUtils.metadata, and add optional default values for get().

Oops, looks like I broke something.
Attachment #8981811 - Flags: review?(mak77)
Status: NEW → ASSIGNED
Comment on attachment 8981811 [details]
Bug 1465380 - Add handling of objects and arrays to PlacesUtils.metadata, and add optional default values for get().

https://reviewboard.mozilla.org/r/247866/#review254454

::: toolkit/components/places/PlacesSyncUtils.jsm:86
(Diff revision 3)
>  
>    /**
>     * Returns the current history sync ID, or `""` if one isn't set.
>     */
>    async getSyncId() {
> -    let syncId = await PlacesUtils.metadata.get(
> +    return PlacesUtils.metadata.get(

the function doesn't need to be async anymore

::: toolkit/components/places/PlacesSyncUtils.jsm:412
(Diff revision 3)
>     */
>    async getSyncId() {
> -    let syncId = await PlacesUtils.metadata.get(
> -      BookmarkSyncUtils.SYNC_ID_META_KEY);
> +    return PlacesUtils.metadata.get(
> +      BookmarkSyncUtils.SYNC_ID_META_KEY, "");
> -    return syncId || "";
>    },

ditto

::: toolkit/components/places/PlacesUtils.jsm:2001
(Diff revision 3)
>     * @param  {String} key
>     *         The metadata key to look up.
> +   * @param  {String|Object|Array} defaultValue
> +   *         Optional. The default value to return if the value is not present,
> +   *         or cannot be parsed.
>     * @return {*}

this should actually be a @resolves

::: toolkit/components/places/PlacesUtils.jsm:2002
(Diff revision 3)
>     *         The metadata key to look up.
> +   * @param  {String|Object|Array} defaultValue
> +   *         Optional. The default value to return if the value is not present,
> +   *         or cannot be parsed.
>     * @return {*}
>     *         The value associated with the key, or `null` if not set.

please add a @rejects

::: toolkit/components/places/PlacesUtils.jsm:2079
(Diff revision 3)
>        return;
>      }
> +
> +    let cacheValue = value;
> +    if (typeof value == "object" && ChromeUtils.getClassName(value) != "Uint8Array") {
> +      value = `${this.jsonPrefix}${this._base64Encode(JSON.stringify(value))}`;

looks like you could just + the 2 strings instead of using a template string
Attachment #8981811 - Flags: review?(mak77) → review+
Pushed by mbanner@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/b489bcf8e20d
Add handling of objects and arrays to PlacesUtils.metadata, and add optional default values for get(). r=mak
https://hg.mozilla.org/mozilla-central/rev/b489bcf8e20d
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla62
Depends on: 1501337
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: