We just had a problem of this sort, with quiz duplication taking many hours, and it turned out to be due to a recently identified critical moodle bug in versions 3.5 and 3.6: MDL-63260 - "Duplicating quiz with random question has exponential questions growth". Every time you duplicate a quiz in a course that has random questions in it, the number of random questions in that course doubles. So if you start with a single random question and over time you duplicate 20 quizzes, you now have around 1 million stray questions. On our server it turned out we had 4 million questions in one course rather than the expected 2000 and quiz duplication (which, like all activity duplication operations involves a backup-restore cycle) was taking hours. Various other operations (e.g. course backups) suffer drastically as well.
The stray questions aren't visible through the web interface but a system administrator can run a database query to check the total number of random questions, e.g.
SELECT count(id) FROM mdl_question WHERE qtype='random';
A (partial) fix was made available at the end of December 2018. It involves running a background task ("Remove unused random questions") to identify and delete such stray questions. It removes up to 10,000 stray questions each run. See MDL-63260 for details. So we pulled the latest version of Moodle, ran the task manually once to see how long it took (7 minutes to delete 10,000 questions) and set the task frequency via the administrator scheduled tasks panel to run every 9 minutes. After 12 hours we're down from 4 million stray questions to just under 1 million. This is faster than expected, which is mildly concerning, but otherwise it's all looking good.