Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent multiple calls to API, even if data not retrieved #35

Open
MikeiLL opened this issue Sep 12, 2021 · 0 comments
Open

Prevent multiple calls to API, even if data not retrieved #35

MikeiLL opened this issue Sep 12, 2021 · 0 comments

Comments

@MikeiLL
Copy link
Owner

MikeiLL commented Sep 12, 2021

We are getting many and frequent calls to the MBO api if the desired key isn't present in the API result.

Perhaps we want to create some kind of transient, even an empty array, for a certain period of time, so that we aren't doing repeat calls for data that isn't forthcoming.

Not sure exactly how that would work yet:

		if ( false === get_transient( 'mz_mbo_services' ) ) {

			$this->get_mbo_results();

			if ( ! is_object( $this->mb ) ) {
				return 'Check your MBO connection.';
			}

			try {
				$result = $this->mb->GetServices();
			} catch ( \Exception $e ) {
				return false;
			}

			if ( array_key_exists( 'Services', $result ) ) {
				if ( ! empty( $result['Services'] ) ) {
					set_transient( 'mz_mbo_services', $result, 86400 );
				}
				if ( empty( $result['Services'] ) ) {
					set_transient( 'mz_mbo_services', array(), 86400 );
				}
			}
		} else {

			$result = get_transient( 'mz_mbo_services' );

		}

Wait... isn't that already happening? Look here:

                               if ( empty( $result['Services'] ) ) {
					set_transient( 'mz_mbo_services', array(), 86400 );
				}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant