This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
The following commit(s) were added to refs/heads/master by this push:
new 430baa37a use $regex instead of re.compile in mongo queries, so it
uses indexes properly. Maybe fixed in current mongo versions
https://jira.mongodb.org/browse/SERVER-26991
430baa37a is described below
commit 430baa37a5ea8cd263bb9b3cee331e636e61438a
Author: Dave Brondsema <[email protected]>
AuthorDate: Wed Feb 21 12:06:19 2024 -0500
use $regex instead of re.compile in mongo queries, so it uses indexes
properly. Maybe fixed in current mongo versions
https://jira.mongodb.org/browse/SERVER-26991
---
Allura/allura/controllers/project.py | 2 +-
Allura/allura/controllers/site_admin.py | 4 ++--
Allura/allura/controllers/trovecategories.py | 6 +++---
Allura/allura/ext/admin/admin_main.py | 4 ++--
Allura/allura/lib/plugin.py | 4 ++--
Allura/allura/model/project.py | 2 +-
ForgeDiscussion/forgediscussion/controllers/forum.py | 2 +-
ForgeUserStats/forgeuserstats/controllers/userstats.py | 2 +-
8 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/Allura/allura/controllers/project.py
b/Allura/allura/controllers/project.py
index 8ddb21da8..f4d8c9865 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -687,7 +687,7 @@ class NeighborhoodAdminController:
if icon is not None and icon != b'':
if self.neighborhood.icon:
self.neighborhood.icon.delete()
- M.ProjectFile.query.remove(dict(project_id=c.project._id,
category=re.compile(r'^icon')))
+ M.ProjectFile.query.remove(dict(project_id=c.project._id,
category={'$regex': r'^icon'}))
save_icon = c.project.save_icon(icon.filename, icon.file,
content_type=icon.type)
if save_icon:
M.AuditLog.log('update neighborhood icon')
diff --git a/Allura/allura/controllers/site_admin.py
b/Allura/allura/controllers/site_admin.py
index 5b41bc94a..07009028b 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -542,9 +542,9 @@ class TaskManagerController:
if state:
query['state'] = state
if task_name:
- query['task_name'] = re.compile(re.escape(task_name))
+ query['task_name'] = {'$regex': re.escape(task_name)}
if host:
- query['process'] = re.compile(re.escape(host))
+ query['process'] = {'$regex': re.escape(host)}
tasks = list(M.monq_model.MonQTask.query.find(query).sort('_id', -1))
for task in tasks:
diff --git a/Allura/allura/controllers/trovecategories.py
b/Allura/allura/controllers/trovecategories.py
index 1c0c14a89..d94d60e42 100644
--- a/Allura/allura/controllers/trovecategories.py
+++ b/Allura/allura/controllers/trovecategories.py
@@ -131,11 +131,11 @@ class TroveCategoryController(BaseController):
if upper:
trove_type = upper.fullpath.split(' :: ')[0]
- fullpath_re = re.compile(fr'^{re.escape(trove_type)} :: ') # e.g.
scope within "Topic :: "
+ fullpath_re = fr'^{re.escape(trove_type)} :: ' # e.g. scope
within "Topic :: "
else:
# no parent, so making a top-level. Don't limit fullpath_re, so
enforcing global uniqueness
- fullpath_re = re.compile(r'')
- oldcat = M.TroveCategory.query.get(shortname=shortname,
fullpath=fullpath_re)
+ fullpath_re = r''
+ oldcat = M.TroveCategory.query.get(shortname=shortname,
fullpath={'$regex': fullpath_re})
if oldcat:
raise TroveAdminException(
diff --git a/Allura/allura/ext/admin/admin_main.py
b/Allura/allura/ext/admin/admin_main.py
index fc2f2ac53..6e8232fc6 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -336,7 +336,7 @@ class ProjectAdminController(BaseController):
c.project.removal = removal
c.project.removal_changed_date = datetime.utcnow()
if 'delete_icon' in kw:
- M.ProjectFile.query.remove(dict(project_id=c.project._id,
category=re.compile(r'^icon')))
+ M.ProjectFile.query.remove(dict(project_id=c.project._id,
category={'$regex': r'^icon'}))
c.project.set_tool_data('allura', icon_original_size=None,
icon_sha256=None)
M.AuditLog.log('remove project icon')
g.post_event('project_updated')
@@ -415,7 +415,7 @@ class ProjectAdminController(BaseController):
if icon is not None and icon != b'':
if c.project.icon:
- M.ProjectFile.query.remove(dict(project_id=c.project._id,
category=re.compile(r'^icon')))
+ M.ProjectFile.query.remove(dict(project_id=c.project._id,
category={'$regex': r'^icon'}))
save_icon = c.project.save_icon(icon.filename, icon.file,
content_type=icon.type)
if not save_icon:
M.AuditLog.log('could not update project icon')
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 47defa5db..d88163284 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -567,8 +567,8 @@ class LocalAuthenticationProvider(AuthenticationProvider):
escaped_underscore = re.escape('_') # changes in py3.x versions #
https://docs.python.org/3/library/re.html#re.escape
un = un.replace(escaped_underscore, '[-_]')
un = un.replace(r'\-', '[-_]')
- rex = re.compile('^' + un + '$')
- return M.User.query.get(username=rex, disabled=False, pending=False)
+ rex = r'^' + un + '$'
+ return M.User.query.get(username={'$regex': rex}, disabled=False,
pending=False)
def set_password(self, user, old_password, new_password):
if old_password is not None and not self.validate_password(user,
old_password):
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 33a675e8a..c302e2487 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -161,7 +161,7 @@ class TroveCategory(MappedClass):
@property
def children(self):
- return sorted(self.query.find({'fullpath': re.compile('^' +
re.escape(self.fullpath) + ' ::')}).all(),
+ return sorted(self.query.find({'fullpath': {'$regex': '^' +
re.escape(self.fullpath) + ' ::'}}).all(),
key=lambda t: t.fullpath.lower())
@property
diff --git a/ForgeDiscussion/forgediscussion/controllers/forum.py
b/ForgeDiscussion/forgediscussion/controllers/forum.py
index 953d40dd0..064135ce0 100644
--- a/ForgeDiscussion/forgediscussion/controllers/forum.py
+++ b/ForgeDiscussion/forgediscussion/controllers/forum.py
@@ -136,7 +136,7 @@ class ForumController(DiscussionController):
user_id=c.user._id,
project_id=c.project._id,
app_config_id=c.app.config._id,
- artifact_index_id=re.compile('^' +
re.escape(forumthread_index_prefix)),
+ artifact_index_id={'$regex': '^' +
re.escape(forumthread_index_prefix)},
)).all()
# get the ForumThread objects from the subscriptions
thread_index_ids = [mbox.artifact_index_id for mbox in
thread_mboxes]
diff --git a/ForgeUserStats/forgeuserstats/controllers/userstats.py
b/ForgeUserStats/forgeuserstats/controllers/userstats.py
index 7efcb512b..7df06f51f 100644
--- a/ForgeUserStats/forgeuserstats/controllers/userstats.py
+++ b/ForgeUserStats/forgeuserstats/controllers/userstats.py
@@ -38,7 +38,7 @@ class ForgeUserStatsCatController(BaseController):
@expose()
def _lookup(self, category, *remainder):
- cat = M.TroveCategory.query.get(shortname=category,
fullpath=re.compile(r'^Topic :: '))
+ cat = M.TroveCategory.query.get(shortname=category,
fullpath={'$regex': r'^Topic :: '})
if not cat:
raise exc.HTTPNotFound
return ForgeUserStatsCatController(category=cat), remainder