This is an automated email from the ASF dual-hosted git repository. dill0wn pushed a commit to branch dw/8565 in repository https://gitbox.apache.org/repos/asf/allura.git
commit 4ddfcc1dfe2e1b4f877ce94c791ec01c02a947f1 Author: Dillon Walls <dillon.wa...@slashdotmedia.com> AuthorDate: Tue Jun 18 18:21:38 2024 -0400 update ming calls from find_and_modify to find_one_and_update --- Allura/allura/lib/custom_middleware.py | 5 +++-- Allura/allura/model/auth.py | 4 ++-- Allura/allura/model/monq_model.py | 4 ++-- Allura/allura/model/notification.py | 8 ++++---- Allura/allura/model/repository.py | 4 ++-- ForgeImporters/forgeimporters/base.py | 8 ++++---- ForgeTracker/forgetracker/model/ticket.py | 4 ++-- 7 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Allura/allura/lib/custom_middleware.py b/Allura/allura/lib/custom_middleware.py index e06f950c1..16ca53479 100644 --- a/Allura/allura/lib/custom_middleware.py +++ b/Allura/allura/lib/custom_middleware.py @@ -326,7 +326,8 @@ class AlluraTimerMiddleware(TimerMiddleware): debug_each_call=False), Timer('ming', ming.odm.odmsession.ODMSession, 'insert_now', 'update_now', 'delete_now', - 'find', 'find_and_modify', 'remove', 'update', 'update_if_not_modified', + 'find', 'find_one_and_update', 'find_one_and_replace', 'find_one_and_delete', + 'remove', 'update', 'update_if_not_modified', 'aggregate', 'group', 'map_reduce', 'inline_map_reduce', 'distinct', ), # Timer('ming', ming.schema.Document, 'validate', @@ -336,7 +337,7 @@ class AlluraTimerMiddleware(TimerMiddleware): # debug_each_call=False), Timer('mongo', pymongo.collection.Collection, 'count', 'find', 'find_one', 'aggregate', 'group', 'map_reduce', - 'inline_map_reduce', 'find_and_modify', + 'inline_map_reduce', 'find_one_and_update', 'find_one_and_replace', 'find_one_and_delete', 'insert', 'save', 'update', 'remove', 'drop'), Timer('mongo', pymongo.cursor.Cursor, 'count', 'distinct', '_refresh'), diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py index 0b73f1b34..cb797e776 100644 --- a/Allura/allura/model/auth.py +++ b/Allura/allura/model/auth.py @@ -217,8 +217,8 @@ class AuthGlobals(MappedClass): @classmethod def get_next_uid(cls): cls.upsert() - g = cls.query.find_and_modify( - query={}, update={'$inc': {'next_uid': 1}}, + g = cls.query.find_one_and_update( + {}, update={'$inc': {'next_uid': 1}}, new=True) return g.next_uid diff --git a/Allura/allura/model/monq_model.py b/Allura/allura/model/monq_model.py index 61ea3d863..17b4aa47e 100644 --- a/Allura/allura/model/monq_model.py +++ b/Allura/allura/model/monq_model.py @@ -199,8 +199,8 @@ class MonQTask(MappedClass): query['time_queue'] = {'$lte': datetime.utcnow()} if only: query['task_name'] = {'$in': only} - obj = cls.query.find_and_modify( - query=query, + obj = cls.query.find_one_and_update( + query, update={ '$set': dict( state='busy', diff --git a/Allura/allura/model/notification.py b/Allura/allura/model/notification.py index 2bd205d35..942a34b66 100644 --- a/Allura/allura/model/notification.py +++ b/Allura/allura/model/notification.py @@ -592,8 +592,8 @@ class Mailbox(MappedClass): next_scheduled={'$lt': now}) def find_and_modify_direct_mbox(): - return cls.query.find_and_modify( - query=q_direct, + return cls.query.find_one_and_update( + q_direct, update={'$set': dict( queue=[], queue_empty=True, @@ -618,8 +618,8 @@ class Mailbox(MappedClass): next_scheduled += timedelta(days=7 * mbox.frequency.n) elif mbox.frequency.unit == 'month': next_scheduled += timedelta(days=30 * mbox.frequency.n) - mbox = cls.query.find_and_modify( - query=dict(_id=mbox._id), + mbox = cls.query.find_one_and_update( + dict(_id=mbox._id), update={'$set': dict( next_scheduled=next_scheduled, queue=[], diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py index c947ec1b3..3266fe0a8 100644 --- a/Allura/allura/model/repository.py +++ b/Allura/allura/model/repository.py @@ -1072,8 +1072,8 @@ class CommitStatus(MappedClass): @classmethod def upsert(cls, **kw): - obj = cls.query.find_and_modify( - query=dict(commit_id=kw.get('commit_id'), context=kw.get('context')), + obj = cls.query.find_one_and_update( + dict(commit_id=kw.get('commit_id'), context=kw.get('context')), update={'$set': kw}, new=True, upsert=True, diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py index 1087bdc40..7c87c6a78 100644 --- a/ForgeImporters/forgeimporters/base.py +++ b/ForgeImporters/forgeimporters/base.py @@ -466,8 +466,8 @@ class ToolImporter(metaclass=ToolImporterMeta): """ limit = config.get('tool_import.rate_limit', 1) pending_key = 'tool_data.%s.pending' % self.classname - modified_project = M.Project.query.find_and_modify( - query={ + modified_project = M.Project.query.find_one_and_update( + { '_id': project._id, '$or': [ {pending_key: None}, @@ -485,8 +485,8 @@ class ToolImporter(metaclass=ToolImporterMeta): to indicate that an import is complete. """ pending_key = 'tool_data.%s.pending' % self.classname - M.Project.query.find_and_modify( - query={'_id': project._id}, + M.Project.query.find_one_and_update( + {'_id': project._id}, update={'$inc': {pending_key: -1}}, new=True, ) diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py index de099a372..01714d071 100644 --- a/ForgeTracker/forgetracker/model/ticket.py +++ b/ForgeTracker/forgetracker/model/ticket.py @@ -139,8 +139,8 @@ class Globals(MappedClass): }) def next_ticket_num(self): - gbl = Globals.query.find_and_modify( - query=dict(app_config_id=self.app_config_id), + gbl = Globals.query.find_one_and_update( + dict(app_config_id=self.app_config_id), update={'$inc': {'last_ticket_num': 1}}, new=True) session(gbl).expunge(gbl)