Skip to content

Commit

Permalink
Revert 'actors' index to leverage 'portal_repository'
Browse files Browse the repository at this point in the history
  • Loading branch information
miknevinas committed Mar 14, 2024
1 parent 50586a9 commit 4016f36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
22 changes: 11 additions & 11 deletions castle/cms/indexing/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,15 @@ def has_custom_markup(image):

@indexer(IItem)
def actors(context):
# Get history of users that have modified an object
# Get history of users that have modified an item
actors = []
ownership = IOwnership(context, None)
if ownership is not None:
for actor in ownership.contributors:
actors.append(actor) if actor not in actors else None
rt = api.portal.get_tool("portal_repository")
history = rt.getHistoryMetadata(context)

for i in range(history.getLength(countPurged=False)):
data = history.retrieve(i, countPurged=False)
actor = data["metadata"]["sys_metadata"]["principal"]
actors.append(actor) if actor not in actors else None

req = getRequest()
if req is not None and not IReindexActive.providedBy(req):
Expand All @@ -235,11 +238,8 @@ def actors(context):
# is not updated until AFTER reindexing. Here we manually
# update the index if the user modified something so it
# can immediately appear on the dashboard
user_id = api.user.get_current().getId()
if (user_id not in ownership.contributors):
ownership.contributors = ownership.contributors + (
user_id.decode('utf8'),)
actors.append(user_id)
current_user = api.user.get_current().getUserName()
actors.append(current_user) if current_user not in actors else None
except Exception:
pass

Expand All @@ -248,7 +248,7 @@ def actors(context):

@indexer(IItem)
def assigned_users(context):
# Get local roles for an object
# Get local roles for an item
assigned_users = []

acl_users = api.portal.get_tool('acl_users')
Expand Down
20 changes: 1 addition & 19 deletions castle/cms/upgrades/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,4 @@ def upgrade_3011(site, logger=CASTLE_LOGGER):


upgrade_3012 = default_upgrade_factory('3012')


def upgrade_3013(site, logger=CASTLE_LOGGER):
# catalog = api.portal.get_tool('portal_catalog')
# catalog.manage_catalogRebuild()


portal_types_tool = api.portal.get_tool('portal_types')

for portal_type in portal_types_tool:
logger.info('reindexing actors and assigned_users for portal_type ' + portal_type)
# this could take a while
for portal_type_brain in api.content.find(portal_type=portal_type):
try:
content_object = portal_type_brain.getObject()
content_object.reindexObject(idxs=['actors', 'assigned_users'])
except Exception:
logger.info('something weird happened with ' + repr(portal_type_brain))
continue
upgrade_3013 = default_upgrade_factory('3013')

0 comments on commit 4016f36

Please sign in to comment.