<commit_before><?php

/**
 *	This provides functionality for the fusion module.
 *	@author <NAME> <<EMAIL>>
 */

class FusionService {

	/**
	 *	These custom tag types will be consolidated into fusion tags.
	 */

	private static $custom_tag_types = array();

	/**
	 *	Determine the existing and configuration defined tag types to consolidate.
	 *
	 *	@return array(string, string)
	 */

	public function getFusionTagTypes() {

		// Determine existing tag types.

		$types = array();
		$classes = ClassInfo::subclassesFor('DataObject');
		unset($classes['FusionTag']);
		foreach($classes as $class) {

			// Determine the tag types to consolidate, based on data objects ending with "Tag".

			if((strpos(strrev($class), strrev('Tag')) === 0)) {

				// Use the title field as a default.

				$types[$class] = 'Title';
			}
		}

		// Determine configuration defined tag types.

		foreach(Config::inst()->get('FusionService', 'custom_tag_types') as $type => $field) {
			if(in_array($type, $classes)) {

				// Use the configuration defined field.

				$types[$type] = $field;
			}
		}
		return $types;
	}

	/**
	 *	Update the searchable content tagging for a specific fusion tag.
	 *
	 *	@parameter <{FUSION_TAG_ID}> integer
	 */

	public function updateTagging($fusionID) {

		// Determine any data objects with the tagging extension.

		$classes = ClassInfo::subclassesFor('DataObject');
		unset($classes['DataObject']);
		$configuration = Config::inst();
		foreach($classes as $class) {

			// Determine the specific data object extensions.

			$extensions = $configuration->get($class, 'extensions', Config::UNINHERITED);
			if(is_array($extensions) && in_array('TaggingExtension', $extensions)) {

				// Determine whether this fusion tag is being used.

				$mode = Versioned::get_reading_mode();
				Versioned::reading_stage('Stage');
				$objects = $class::get()->filter('FusionTags.ID', $fusionID);

				// Update the searchable content tagging for these data objects.

				if($class::has_extension($class, 'Versioned')) {

					// These data objects are versioned.

					foreach($objects as $object) {

						// Update the staging version.

						$object->writeWithoutVersion();

						// Update the live version.

						Versioned::reading_stage('Live');
						if($live = $class::get()->byID($object->ID)) {
							$live->writeWithoutVersion();
						}
						Versioned::reading_stage('Stage');
					}
				}
				else {

					// These data objects are not versioned.

					foreach($objects as $object) {
						$object->write();
					}
				}
				Versioned::set_reading_mode($mode);
			}
		}
	}

}<commit_msg>Improving searchable content tagging performance.<commit_after><?php

/**
 *	This provides functionality for the fusion module.
 *	@author <NAME> <<EMAIL>>
 */

class FusionService {

	/**
	 *	These custom tag types will be consolidated into fusion tags.
	 */

	private static $custom_tag_types = array();

	/**
	 *	Determine the existing and configuration defined tag types to consolidate.
	 *
	 *	@return array(string, string)
	 */

	public function getFusionTagTypes() {

		// Determine existing tag types.

		$types = array();
		$classes = ClassInfo::subclassesFor('DataObject');
		unset($classes['FusionTag']);
		foreach($classes as $class) {

			// Determine the tag types to consolidate, based on data objects ending with "Tag".

			if((strpos(strrev($class), strrev('Tag')) === 0)) {

				// Use the title field as a default.

				$types[$class] = 'Title';
			}
		}

		// Determine configuration defined tag types.

		foreach(Config::inst()->get('FusionService', 'custom_tag_types') as $type => $field) {
			if(in_array($type, $classes)) {

				// Use the configuration defined field.

				$types[$type] = $field;
			}
		}
		return $types;
	}

	/**
	 *	Update the searchable content tagging for a specific fusion tag.
	 *
	 *	@parameter <{FUSION_TAG_ID}> integer
	 */

	public function updateTagging($fusionID) {

		// Determine any data objects with the tagging extension.

		$classes = ClassInfo::subclassesFor('DataObject');
		unset($classes['DataObject']);
		$configuration = Config::inst();
		foreach($classes as $class) {

			// Determine the specific data object extensions.

			$extensions = $configuration->get($class, 'extensions', Config::UNINHERITED);
			if(is_array($extensions) && in_array('TaggingExtension', $extensions)) {

				// Determine whether this fusion tag is being used.

				$mode = Versioned::get_reading_mode();
				Versioned::reading_stage('Stage');
				$objects = $class::get()->filter('FusionTags.ID', $fusionID);

				// Update the searchable content tagging for these data objects.

				if($class::has_extension($class, 'Versioned')) {

					// These data objects are versioned.

					foreach($objects as $object) {

						// Update the staging version.

						$object->writeWithoutVersion();
					}
					Versioned::reading_stage('Live');
					$objects = $class::get()->filter('FusionTags.ID', $fusionID);
					foreach($objects as $object) {

						// Update the live version.

						$object->writeWithoutVersion();
					}
				}
				else {

					// These data objects are not versioned.

					foreach($objects as $object) {
						$object->write();
					}
				}
				Versioned::set_reading_mode($mode);
			}
		}
	}

}
{'fraction_non_alphanumeric': 0.14402277039848196, 'fraction_numerical': 0.0003795066413662239, 'mean_word_length': 3.36341059602649, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1055037', 'n_tokens_mistral': 1914, 'n_tokens_neox': 1505, 'n_words': 417}