We have created an intranet application with MODx. It works well enough, but it doesn't run very fast. I'm working on profiling now to determine the slowdown areas, but I think I already know one of the big ones - and I have no idea what to do about it.
The application users have different company associations and permission levels, which are associated and calculated by custom logic. (Logic that's too complicated to outline here, but it doesn't relate directly to the question.) To facilitate using this info one the frontend, for forms, content, etc., we have a plugin that goes through it and sets it as placeholders.
Now, all of this information is different for each user in the system, and some can change based on what the user selects during his session. (For example, the user can switch the "active branch" and have it persist through the session.) So, to ensure that the information is up-to-date, we have set the plugin to run onWebPageInit. This means that a whole raft of custom logic is running every time a page loads; hence my suspicion that this plugin is responsible for much of the sluggishness on the interface.
Now that I think about it, active branch is the only piece of placeholder info that could change during the user session, and it is stored in a cookie. So putting it in a placeholder would take up very little power, if we could only find a way to "cache" the other custom placeholders - the ones that only change per user. (Among these are the placeholders set by the MODX Profile snippet, which we're running from the plugin to make all the user fields available to the interface.)
So my question is, can anyone suggest a good way to "cache" these user-related placeholders - to store them per session, per user, so that we don't have to re-run the plugin every time a page loads?
Any suggestions would be greatly appreciated.
Jason
-
☆ A M B ☆
- 24,524 Posts
What about User Settings? Like System Settings and Context Settings, they are accessed via [[++setting]] tags rather than placeholders.
Can you calculate them in a plugin attached to OnUserFormSave and save them as User Settings? Creating new Settings can be really slow, so you definitely don't want to do it on page loads if you can avoid it.
If you need them to be per-session, they could still be User Settings calculated in OnWebLogin or they could be $_SESSION variables. I think $_SESSION variables would be a little faster.
I like the $_SESSION variables idea. Storing data that could change per session in user settings seems a bit counter-intuitive.
Jason
-
☆ A M B ☆
- 24,524 Posts
Ah, of course. I missed the part about it being dynamic. Definitely $_SESSION is the way to go then. You can use fastField to quickly fetch SESSION values, by the way.
@sottwell Thanks for the heads-up on fastField. I am always hearing about handy plugins I never knew of before.
@opengeek getCache has already helped to speed up this particular site, used to optimize Wayfinder. But how would I use it with a plugin?
Jason
-
☆ A M B ☆
- 24,524 Posts
FastField is not a plugin. It's an actual replacement for the MODx parser. As of Revo 2.2.7 the ability to specify a custom parser in System Settings was added, and as far as I know fastField is the first one. So it doesn't have much of a performance hit if any, it simply extends the original parser to add another MODx tag [[#...]].