views:

52

answers:

2

I've been asked to review a wordpress plugin of sorts and try to find ways of making it faster. The premise of this plugin is basically to store a bunch of users and shifts and appointments and whatnot. It involves a five major variables, Start of week, day of week, user, resource, and appointment.

Currently, it's using a horrendous method of storing the information by creating a string that basically does:

"var1::var2::var3::var4::var5;;var1::var2...."

Everytime someone needs to look at the calendar, it goes into that string and explodes it, and traverses through the entire thing.

What would be the best way to organize the data so that I can just say, start of week is this, day of week is this, give me an array with the rest of the variables in their respective/related positions?

+1  A: 

Hm. The string may look horrendous (many things in Wordpress do :-), but from a performance perspective I hardly think that is the core of the problem. String operations are still quite fast, and at the end of the day, even if you use some sophisticated storage class, your data will be stored in some way like this, unless you are using a database.

I would use a profiler to find out what the bottlenecks are. Maybe they are not in the PHP code, but in the Javascript that is done on top of it?

Pekka
A: 

I agree that this may not be your bottleneck -- consider some profiling for better data. But, if you are going to store the data as a string, I think serializing your data structure with the built-in functions is a better idea than doing it by hand. Check out serialize(), or json_encode() if the data might be used by non-PHP apps.

Funkatron