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

fix EnvironmentManager updateEnv #60

Merged
merged 3 commits into from
May 4, 2024

Conversation

Timo972
Copy link

@Timo972 Timo972 commented Apr 19, 2024

This PR fixes an issue inside the updateEnv method of the EnvironmentManager.

Previous output when updating mail config:

# ...
""""""""MAIL_FROM_NAME="XXX"""""""""

MAIL_FROM_NAME="XXX"

Fixed output:

# ...
MAIL_FROM_NAME="XXX"

I have also added the MAIL_FROM_NAME and MAIL_FROM_ADDRESS keys to the .env.example file to be able to set these for the Docker container. The inject.sh file inside the Docker container only replaces existing env vars and since these two are not existing in the example, one cannot set them.

@gdarko
Copy link

gdarko commented Apr 20, 2024

Hey @Timo972

Regarding the encode() call, can you give more context on the removed line? Thanks.

I will wait on the Docker change because we are working to re-factor the Docker code to fix some ongoing issues.

Best Regards,
Darko

@Timo972
Copy link
Author

Timo972 commented Apr 22, 2024

Hey @gdarko,

I will elaborate on the logic of the updateEnv method.

In the current state we accept a dictionary which shall either be appended to or updated in the environment array. In order to achieve this we are looping over the dictionary. Inside one iteration of this loop we iterate the WHOLE environment array and check if the key of the env string matches the current $data_key. In case it matches, we are replacing the env array value with our newly encoded key=value pair. Otherwise (this is what I deleted) we re-encode the WHOLE environment line which means for example 'MAIL_FROM_NAME="XX X"' turns into '"MAIL_FROM_NAME="XX X""'. This is flawed behaviour, since if the keys don't match we shouldn't touch the env line at all. The reason it worked so far is because the encode method does nothing unless it detects a special character, which is often only the case for the MAIL_FROM_NAME env.

Now that I took another look at it, I noticed we could reduce the runtime even further: Right now its O(m*n) because of the two nested for loops where m equals the length of the dictionary and n equals the count of the environment variables. We could cut it down to O(m+n) by simply iterating the environment array first and updating all values that match and afterwards appending the missing env's to the end.
However I'm not sure if its worth the effort though since the updateEnv method is only called for updating settings.

Best regards

@gdarko gdarko merged commit 6ea112c into InvoiceShelf:master May 4, 2024
5 checks passed
@gdarko
Copy link

gdarko commented May 4, 2024

Hey @Timo972 - I reviewed this throughly. Thank you so much for the dedication. Merging it now.

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

Successfully merging this pull request may close these issues.

None yet

2 participants