Sim
Well-known member
I want to add some options to account preferences as part of an addon I'm developing.
Trying to work out the potential ramifications / benefits of different approaches I'm considering in relation to storing the data.
I see two ways of approaching this:
Option 1 - adding a new column to user_option table means the data is loaded along with all other options. But I generally prefer to avoid modifying core tables, which is why I am considering option 2.
Option 2 - potentially adds another query, so care would be needed if this will be loaded frequently - but in my case, it's only going to be loaded as part of a background job, so I'm not concerned about database hits.
I'm not sure which approach is going to require more coding work - if I add a new column to the existing table, I need to extend all of the User Option save functionality to ensure the data gets stored when preferences are updated. If I add a new table, I only need to implement enough to store and retrieve that data when required - but there's potentially more work involved in saving preferences since I can't just piggyback on existing code.
My main driver for wanting to use a separate table is 1) less chance of making a mess when installing/upgrading/removing the addon if my Setup routine isn't perfect ... and 2) potentially less work if there are future changes to the xf_user_option table which might impact on my addon.
I'm guessing it's largely going to come down to personal preference?
How does everyone else approach this? Are there any recommendations from the devs?
I note that both XFMG and XFRM both add columns to the xf_user table directly - but those are mostly count fields rather than preference fields, so it makes sense for them to be there.
Trying to work out the potential ramifications / benefits of different approaches I'm considering in relation to storing the data.
I see two ways of approaching this:
- add a new column to the xf_user_option table and extend the UserOption entity
- add a new table with corresponding new entity and add that as a new relation to the User entity
Option 1 - adding a new column to user_option table means the data is loaded along with all other options. But I generally prefer to avoid modifying core tables, which is why I am considering option 2.
Option 2 - potentially adds another query, so care would be needed if this will be loaded frequently - but in my case, it's only going to be loaded as part of a background job, so I'm not concerned about database hits.
I'm not sure which approach is going to require more coding work - if I add a new column to the existing table, I need to extend all of the User Option save functionality to ensure the data gets stored when preferences are updated. If I add a new table, I only need to implement enough to store and retrieve that data when required - but there's potentially more work involved in saving preferences since I can't just piggyback on existing code.
My main driver for wanting to use a separate table is 1) less chance of making a mess when installing/upgrading/removing the addon if my Setup routine isn't perfect ... and 2) potentially less work if there are future changes to the xf_user_option table which might impact on my addon.
I'm guessing it's largely going to come down to personal preference?
How does everyone else approach this? Are there any recommendations from the devs?
I note that both XFMG and XFRM both add columns to the xf_user table directly - but those are mostly count fields rather than preference fields, so it makes sense for them to be there.