Architecture, Array vs SQL

Re: Architecture, Array vs SQL

av Mark Johnson -
Antall svar: 0
Bilde av Core developers Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av Plugin developers
- I tried to do everything with API calls, parsing the needed data out of them. I could also put everything together in one self made SQL Query with some Joins. Which option is the better one?
This is a bit of a toss-up between raw performance and maintainability.  Sticking everything into a big SQL query will probably be more performant (as long as you write the SQL well), but it will probably be less obvious what's going on when you or someone else comes back to this code at a later date. Also, API functions will take care of any underlying changes to the database structure, which you'd otherwise have to watch out for.

- Should I hold all the data in arrays or create and insert a new DB table? I guess arrays would have the better performance but the database solution maybe prettier and easier to maintain?
- At the moment Im executing everything in the get_content() function in the main file, so everything is loaded all the time with every site refresh, which is not optimal regarding performance and modularity I guess. How can I design that better?
- With a database solution I would calculate everything and store it in a table. Then I would have to listen to events and everytime an activity gets graded or something in the course changes, like a new activity gets created, I would have to update the table in the database. Does that make sense?
Have you looked at caching?  It sounds like that would be better suited to this case than storing the display data in the database.  You can just stick the display data in the cache, then check if it's there before doing new queries/API calls.  You can also define events which will automatically invalidate data in the cache.