DB changes too slow for page reload

DB changes too slow for page reload

by Stephan L -
Number of replies: 2

Hello!

I wrote a block plugin where users are able to create sticky notes. These notes are getting stored to DB when the user presses the save button or leaves the page. All database store operations are performed by a PHP and are invoked by Ajax requests.

However, when someone edits a note and refreshes the page, the note is getting saved to database, but it still represents the unedited version. It seems like the database query was faster than the record update earlier, because a new page refresh displays the edited note.

Is there a way to wait for pending database updates?

Average of ratings: -
In reply to Stephan L

Re: DB changes too slow for page reload

by Stephan L -
I tried out to use the moodle transaction, but it doesn't seem to solve the issue.
In reply to Stephan L

Re: DB changes too slow for page reload

by Renaat Debleu -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
I presume this is a cache problem, as long as the cache you use is not cleared, all data is served from the cache instead form the database. Perhaps a brute force rebuild_course_cache($courseid, true); can help with a refresh, but you will need to find a more subtle way to keep your block performant.