Notifications::prefetch()

Description #

Prefetch posts, comments and other data.

Source #

File: addons/notifications/query.php

	public function prefetch() {
		foreach ( (array) $this->objects as $key => $noti ) {
			if ( ! empty( $noti->noti_ref_id ) ) {
				$current_verb = $this->verb_args( $noti->noti_verb );

				if ( in_array( $current_verb['ref_type'], array( 'question', 'answer', 'post' ), true ) ) {
					$this->add_prefetch_id( 'post', $noti->noti_ref_id, $key );
				}

				if ( 'comment' === $current_verb['ref_type'] ) {
					$this->add_prefetch_id( 'comment', $noti->noti_ref_id, $key );
				}

				if ( 'reputation' === $current_verb['ref_type'] ) {
					$this->add_prefetch_id( 'reputation', $noti->noti_ref_id, $key );
				}
			}

			if ( ! empty( $noti->noti_actor ) ) {
				$this->add_prefetch_id( 'user', $noti->noti_actor );
			}
		}

		$this->prefetch_posts();
		$this->prefetch_comments();
		$this->prefetch_actors();
		$this->prefetch_reputations();
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment