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

Removed not necessary data loading. #326

Conversation

szymekjanaczek
Copy link
Contributor

Hi, @Webklex

I always have been impolite, so the long waiting time for a message confused me. After a quick research, I found the problem - this line is (in my opinion) not necessary because we don't use msgn - only uid.
What do you think?

Effect? Loading time from 6 seconds reduced to 0.6 seconds.

Greetings!

@Webklex
Copy link
Owner

Webklex commented Nov 14, 2022

Hi @szymekjanaczek ,
wow that's a lot!

I remember adding it initially to make sure the user has always access to the message number and uid. However, I never noticed such an huge delay.

I'm afraid simply removing it could cause some havoc, if someone was relaying on the message number but is fetching in "uid mode". I agree with removing them and perhaps adding the "fetch message number" logic here:
https://github.com/Webklex/php-imap/blob/master/src/Message.php#L344-L350

If someone still tries to access it and Message::$msgn isn't set, fetch it instead. That way everyone's happy :)

Thank you for digging and discovering this!

@Webklex Webklex added the enhancement New feature or request label Nov 14, 2022
@szymekjanaczek
Copy link
Contributor Author

Hello!

Thanks for the comment - that's why I asked for your opinion - from creator ;)

I'm not sure what you mean here:

I agree with removing them and perhaps adding the "fetch message number" logic here:
https://github.com/Webklex/php-imap/blob/master/src/Message.php#L344-L350

What exactly should I add inside this method? Or maybe would you like me to add a new method like:

public function loadMsgn(int uid): void {
    $this->msgn = $this->client->getConnection()->getMessageNumber($this->uid);
}

Please, let me know.

Greetings!

@Webklex
Copy link
Owner

Webklex commented Nov 14, 2022

I thought something like this:

/**
 * Get an available message or message header attribute
 * @param $name
 *
 * @return int|mixed|Attribute|null
 * @throws Exceptions\ConnectionFailedException
 * @throws Exceptions\MessageNotFoundException
 */
public function get($name) {
    if(isset($this->attributes[$name])) {
        return $this->attributes[$name];
    }else if ($name === "msgn") {
        $this->attributes[$name] = $this->client->getConnection()->getMessageNumber($this->uid);
        return $this->attributes[$name];
    }

    return $this->header->get($name);
}

But I haven't tested if this actually works. If it does, $message->msgn should fetch the associated message number and cache it as an attribute if it wasn't fetched before.

I wouldn't mind moving this logic block into it's own method. Scrutinizer will probably thank you for that :)

Best regards,

Webklex added a commit that referenced this pull request Jan 2, 2023
@Webklex
Copy link
Owner

Webklex commented Jan 2, 2023

Hi @szymekjanaczek ,
it's fixed :)

95925da

Best regards,

@Webklex Webklex closed this Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants