<commit_before><?php

/**
 * This job is created when sending notifications to the target users.  The purpose
 * of this job is to delete older notifications when the number of notifications a
 * user has is more than $wgEchoMaxUpdateCount, it does not make sense to have tons
 * of notifications in the history while users wouldn't bother to click 'load more'
 * like 100 times to see them. What we gain from this is we could run expensive
 * queries otherwise that would requires adding index and data denormalization.
 *
 * The initial job contains multiple users, which will in turn have individual jobs
 * queued for them.
 */
class EchoNotificationDeleteJob extends Job {

	/**
	 * UserIds to be processed
	 * @var int[]
	 */
	protected $userIds = array();

	/**
	 * @param Title $title
	 * @param array $params
	 */
	public function __construct( $title, $params ) {
		parent::__construct( __CLASS__, $title, $params );
		$this->userIds = $params['userIds'];
	}

	/**
	 * Run the job of finding & deleting older notifications
	 */
	public function run() {
		global $wgEchoMaxUpdateCount;
		if ( count( $this->userIds ) > 1 ) {
			// If there are multiple users, queue a single job for each one
			$jobs = array();
			foreach ( $this->userIds as $userId ) {
				$jobs[] = new EchoNotificationDeleteJob( $this->title, array( 'userIds' => array( $userId ) ) );
			}
			JobQueueGroup::singleton()->push( $jobs );
			return true;
		}

		$notifMapper  = new EchoNotificationMapper();
		$targetMapper = new EchoTargetPageMapper();

		$userId = $this->userIds[0];
		$user = User::newFromId( $userId );
		$notif = $notifMapper->fetchByUserOffset( $user, $wgEchoMaxUpdateCount );
		if ( $notif ) {
			$res = $notifMapper->deleteByUserEventOffset(
				$user, $notif->getEvent()->getId()
			);
			if ( $res ) {
				$res = $targetMapper->deleteByUserEventOffset(
					$user, $notif->getEvent()->getId()
				);
			}
			if ( $res ) {
				$notifUser = MWEchoNotifUser::newFromUser( $user );
				$notifUser->resetNotificationCount( DB_MASTER );<commit_msg>Avoid warnings on older queued EchoNotificationDeleteJobs<commit_after><?php

/**
 * This job is created when sending notifications to the target users.  The purpose
 * of this job is to delete older notifications when the number of notifications a
 * user has is more than $wgEchoMaxUpdateCount, it does not make sense to have tons
 * of notifications in the history while users wouldn't bother to click 'load more'
 * like 100 times to see them. What we gain from this is we could run expensive
 * queries otherwise that would requires adding index and data denormalization.
 *
 * The initial job contains multiple users, which will in turn have individual jobs
 * queued for them.
 */
class EchoNotificationDeleteJob extends Job {

	/**
	 * UserIds to be processed
	 * @var int[]
	 */
	protected $userIds = array();

	/**
	 * @param Title $title
	 * @param array $params
	 */
	public function __construct( $title, $params ) {
		parent::__construct( __CLASS__, $title, $params );
		$this->userIds = $params['userIds'];
	}

	/**
	 * Run the job of finding & deleting older notifications
	 */
	public function run() {
		global $wgEchoMaxUpdateCount;
		if ( count( $this->userIds ) > 1 ) {
			// If there are multiple users, queue a single job for each one
			$jobs = array();
			foreach ( $this->userIds as $userId ) {
				$jobs[] = new EchoNotificationDeleteJob( $this->title, array( 'userIds' => array( $userId ) ) );
			}
			JobQueueGroup::singleton()->push( $jobs );
			return true;
		}

		$notifMapper  = new EchoNotificationMapper();
		$targetMapper = new EchoTargetPageMapper();

		// Back-compat for older jobs which used array( $userId => $userId );
		$userIds = array_values( $this->userIds );
		$userId = $userIds[0];
		$user = User::newFromId( $userId );
		$notif = $notifMapper->fetchByUserOffset( $user, $wgEchoMaxUpdateCount );
		if ( $notif ) {
			$res = $notifMapper->deleteByUserEventOffset(
				$user, $notif->getEvent()->getId()
			);
			if ( $res ) {
				$res = $targetMapper->deleteByUserEventOffset(
					$user, $notif->getEvent()->getId()
				);
			}
			if ( $res ) {
				$notifUser = MWEchoNotifUser::newFromUser( $user );
				$notifUser->resetNotificationCount( DB_MASTER );
{'fraction_non_alphanumeric': 0.12296819787985866, 'fraction_numerical': 0.002355712603062426, 'mean_word_length': 3.7388392857142856, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, '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': '3505463', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1262, 'n_words': 433}