Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Preferences id cleanup #3018

Merged
merged 9 commits into from
Mar 11, 2013
Merged

Conversation

WebsiteDeveloper
Copy link
Contributor

Cleaned up the preferences ids
See #3016

@TomMalbran
Copy link
Contributor

Doing this would also require a 1 time only function (that should be removed in a Sprint or 2) to move the preferences from the old ids to the new ones and removing the preferences on the old ids, so that all the preferences are conserved.

@WebsiteDeveloper
Copy link
Contributor Author

yeah you're right i didn't think of that.
work in progress...

@WebsiteDeveloper
Copy link
Contributor Author

@TomMalbran i added a migration function
when this gets merged i will also open an issue to remove those in a sprint or two

@TomMalbran
Copy link
Contributor

Nice work. I am just seeing lots of repeated code. Maybe to simplify it you could just call handleClientIdChange with the new prefs and just the id of the old ones and inside handleClientIdChange check if it wasn't done before as you did and if the old preferences are saved (if you just call getPreferenceStorage with a non-existent preference you will be creating a new storage), do the same copy and at the end you could do a delete prefStorage[oldClientID] just to cleanup the old now unused preferences.

@WebsiteDeveloper
Copy link
Contributor Author

currently it doesn't really work because sometimes old properties do not exist (with empty local storage) and i get an error because some values are undefined.
i'll try to fix that as soon as possible

@WebsiteDeveloper
Copy link
Contributor Author

what is interesting, is that the problem fixes itself when restarting brackets,
then all works fine, but the prefs get trashed one time which isn't preferable.

@TomMalbran
Copy link
Contributor

Would it be solved with something like this?

function handleClientIdChange(newPrefs, oldPrefsID) {
    if (!newPrefs.getValue("newClientID") && prefStorage[oldPrefsID]) {
        var oldPrefs = getPreferenceStorage(oldPrefsID);
        var data = oldPrefs.getAllValues();
        newPrefs.setAllValues(data, false);
        delete prefStorage[oldPrefsID];
        newPrefs.setValue("newClientID", true);
    }
}

And then just call PreferencesManager.handleClientIdChange(_prefs, oldPrefsID) from each module.

@WebsiteDeveloper
Copy link
Contributor Author

I tried something like this but the problem is when somebody would newly install brackets or open brackets with a clean local storage, it would break because the setAllValues method reports the value undefined as invalid.
I tried another workaround which fixed the startup problem but didn't preserve the old prefs.
I will be further investigating.

@TomMalbran
Copy link
Contributor

I just checked that function I wrote with:
handleClientIdChange(getPreferenceStorage("com.adobe.brackets.DocumentManager"), "preferences");
And I got no errors, knowing that preferences wasn't saved as a key before.

@WebsiteDeveloper
Copy link
Contributor Author

@TomMalbran would you want to test this?
it works for me.

@TomMalbran
Copy link
Contributor

I could give it a try later.

Right now I don't think that the Preference ID from PreferencesManager should be changed, since that is actually the localStorage key and everything else is stored in an object that is stringifyed and stored as the value associated with that key. I would leave that one as how it is.

@WebsiteDeveloper
Copy link
Contributor Author

in my opinion it is better to change that in the PreferencesManager too because so it all becomes more consistent, and as it doesn't add an awfull lot of work i think it's ok.

@TomMalbran
Copy link
Contributor

But is not actually a Preference Storage key associated with the PreferenceManager file, is just the only Local Storage key used, so it can be different to every other key and there wont be any real collision problem with it.

@WebsiteDeveloper
Copy link
Contributor Author

yeah i'll just revert that change so there are fewer changes

@ghost ghost assigned redmunds Mar 8, 2013
@@ -49,7 +49,7 @@ define(function main(require, exports, module) {
UrlParams = require("utils/UrlParams").UrlParams,
Strings = require("strings");

var PREFERENCES_KEY = "com.adobe.brackets.live-development";
var PREFERENCES_CLIENT_ID = "com.adobe.brackets." + module.id;
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of repeating this string everywhere, there should be a getClientId(moduleId) function in PreferencesManager.

@redmunds
Copy link
Contributor

This looks good, but there's a merge conflict, so I can't test it.

@WebsiteDeveloper
Copy link
Contributor Author

@redmunds i resolved the merge conflict and added a getClientId function
i'll open an issue for the cleanup once this is merged

@redmunds
Copy link
Contributor

Looks good. Merging.

redmunds added a commit that referenced this pull request Mar 11, 2013
@redmunds redmunds merged commit fe28cf4 into adobe:master Mar 11, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants