JhonDean / moodle-local_stoodle

Other
0 stars 0 forks source link

DB requests logic improvements #35

Open volodymyrdovhan opened 2 weeks ago

volodymyrdovhan commented 2 weeks ago

Hello,

some of your plugin logic can be improved. For example, requests to the DB. I found some requests to DB in a loop. This can be improved by preparing data in collections/array and then bulk insert/update records.

image

In this specific example, you can retrieve all questions in one request and all questions options in another request - and then prepare data to insert/delete.

In addition, you can use some bulk insert DB methods, like https://moodledev.io/docs/4.5/apis/core/dml#insert_records And wrap this all in a transaction: https://moodledev.io/docs/4.5/apis/core/dml#delegated-transactions

Thanks