I am creating a module on a site that allows users to reserve space, by the half hour, in roughly 10 different spaces. They can book a max of six months out from the current date. I am trying to figure out the best way to keep track of which timeslots are available for each space as the reservations are made.

My initial logic was to create custom post meta (each space is a post) so, for instance, if a space has 12 hours of availability in a day, it would have 24 post meta entries, each one structured like so:

    'slot_1481258220' => //the slot's starting timestamp, prefixed
            'slotStatus' => 'open', //open or filled
            'slotUser' => 123, //ID of the user that reserved the slot
            'ect' => //Other meta data as needed

But then I got to thinking how many pieces of data that actually is and am worried about cluttering the database. The rough math, considering 10 spaces, 12 hours per day, 7 days per week, for a solid 6 months out is over 43,000 separate meta data arrays.

A couple thoughts I had:

  • I could run a cron every day that deletes any slots that are in the past and were never reserved.
  • Each space's meta data would be created in one big chunk (on the first creation of the space) and then each month a cron would run to add additional meta data for the next month out, so it's always a rolling 6 months. This bloats the database even more though.

So, my questions is, am I worried about nothing? Is that many pieces of meta data not really a big deal? If it is a big deal, which I suspect, what is a better method of handling something like this?

  • Whether or not it's 'too much' data is just function of your hosting specs. Knowing your storage capacity and how much space each booking takes up, you can guestimate how often you'll need to run that cron job. But 43,000 rows in the post meta table isn't too much more than the average wp site, for which $5-$10 per month hosting will usually suffice – Dan. Dec 9 '16 at 7:26
  • I would be more concerned with performance than size. Metadata is a very simple object ID/key-based index lookup. Considering you're dealing with bookings/transactions (not necessarily payments), it sounds like you would be better off looking at a custom table. If you could explain the concept of spaces I could try and suggest a schema. – TheDeadMedic Dec 9 '16 at 16:19
  • Thanks both. @TheDeadMedic I've definetely been reading elsewhere that it's more about HOW I pull data out than it is how much I have in there, so I think I just need to be smart about how I do my queries. To explain "Spaces" further (the post type is "space") they are rooms that are able to be rented for rehearsals and classes by the half-hour increment (within a time range each day). – Eckstein Dec 9 '16 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.