• Just wanted to get some other opinions on what everyone thinks might be the most efficient ways of accomplishing the following.

    So I have been working on a react-based app that takes advantage of custom endpoints via the REST API to interact with all sorts of CPT and taxonomy data within a WP backend. To accomplish this, the data for each post is stored as a json object within that post’s meta field labeled json. Then if specified, another json object is created including the post’s ID as well as taxonomy data and adds it to another json object which contains a list of all posts for that CPT. This json object is stored as a transient.

    For instance, for a CPT labeled ‘courses’, whenever an admin adds or edits a course, all of the custom field values, etc. will be encoded as json and saved within that course’s json post meta. Right after the post meta is saved, the courses_index transient is retrieved using get_transient(), and that courses ID and other relevant data is added to the index. So we have done two things, converted all info we need for that course into a json object, and also added that course and its taxonomy info to a json index which lists all of the courses on the system. Necessary steps are also taken when the courses is deleted or reverts to a status other than published to remove it from the index.

    The purpose here is to avoid complex WP_Querys on the fly when interacting with the frontend. To use the basic example above, say a user navigates to a “Courses” screen which initially lists all courses as well as provides a filter to narrow by a taxonomy. Instead of running a query, the app simply retrieves the json index that is stored as a transient, parses and stores that index within the component’s state, and then renders a list of the courses based on that data. Also, then when using the filter we only have to run a function to filter the index of courses we have stored within the state.

    Again, the point of this is to reduce the load on the database as much as possible. Although the above example is the most basic of the actual use-cases within the app, I think it is most clear.

    So I am curious to get some thoughts on this and some advantages/disadvantages from using queries vs get_transient(), particularly in terms of scalability in maintaining the indexes. In your opinion, is the above the best approach?

    • This topic was modified 6 years, 3 months ago by Kevin.
    • This topic was modified 6 years, 3 months ago by Kevin.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Data storage for JS app using WP REST API’ is closed to new replies.