@@ -137,8 +137,21 @@ void changes_process_identifiers (Webserver_Request& webserver_request,
137137}
138138
139139
140+ // This mutex ensures that only one single process can generate the changes modifications at any time.
141+ std::timed_mutex mutex;
142+
143+
140144void changes_modifications ()
141145{
146+ // Ensure only one process at any time generates the changes,
147+ // even if multiple order to generate then were given by the user.
148+ std::unique_lock<std::timed_mutex> lock (mutex, std::defer_lock);
149+ if (!lock.try_lock_for (std::chrono::milliseconds (200 ))) {
150+ Database_Logs::log (" Change notifications: Skipping just now because another process is already generating them" , Filter_Roles::translator ());
151+ return ;
152+ }
153+
154+
142155 Database_Logs::log (" Change notifications: Generating" , Filter_Roles::translator ());
143156
144157
@@ -192,7 +205,6 @@ void changes_modifications ()
192205 // At the same time, produce change statistics per user.
193206
194207 std::vector <std::string> users = database::modifications::getUserUsernames ();
195- if (!users.empty ()) Database_Logs::log (" Change notifications: Per user" , Filter_Roles::translator ());
196208 for (const auto & user : users) {
197209
198210 // Total changes made by this user.
@@ -213,7 +225,9 @@ void changes_modifications ()
213225 // Go through the chapters in that book.
214226 const std::vector <int > chapters = database::modifications::getUserChapters (user, bible, book);
215227 for (auto chapter : chapters) {
216-
228+
229+ Database_Logs::log (" Change notifications: User " + user + " - Bible " + bible + " " + filter_passage_display (book, chapter, " " ), Filter_Roles::translator ());
230+
217231 // Get the sets of identifiers for that chapter, and set some variables.
218232 const std::vector <database::modifications::id_bundle> IdSets = database::modifications::getUserIdentifiers (user, bible, book, chapter);
219233 int reference_new_id {0 };
0 commit comments