Skip to content

Change GetUsersFromProject to only return arrays#1619

Merged
williamjallen merged 2 commits into
masterfrom
fix_500_error_email_manageCoverage
Aug 7, 2023
Merged

Change GetUsersFromProject to only return arrays#1619
williamjallen merged 2 commits into
masterfrom
fix_500_error_email_manageCoverage

Conversation

@josephsnyder
Copy link
Copy Markdown
Member

When there are no users linked to a project coverage file, the GetUsersFromProject function returns false, assuming that an empty query_result means an error. Returning false created a 500 error when the caller function attempted to loop over the return.

Change the function to use Laravel's query system and eliminate the places where boolean values were returned.

@josephsnyder josephsnyder force-pushed the fix_500_error_email_manageCoverage branch from 39af129 to ed5866c Compare August 4, 2023 18:14
Comment on lines +302 to +305
return DB::table('coveragefilepriority')
->join('coveragefile2user', 'coveragefilepriority.id', '=', 'coveragefile2user.fileid')
->where('coveragefilepriority.projectid', '=', intval($this->ProjectId))
->pluck('userid')->toArray();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add a DISTINCT clause to this query to reduce the size of the result array? It's in the original query, but I'm not sure if it's necessary or not.

* @return array<int>
*/
public function GetUsersFromProject(): array|false
public function GetUsersFromProject(): array
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is only used in one location, and this change makes the function rather trivial. The query doesn't even really relate to this model anyway...

Would it make sense to just eliminate this function and inline the contents?

When there are no users linked to a project coverage file, the
GetUsersFromProject function returns false, assuming that an empty
query_result means an error.  Returning false created a 500 error
when the caller function attempted to loop over the return.

Since it is called in one place only, remove the function and set the DB
call in the controller directly.
@josephsnyder josephsnyder force-pushed the fix_500_error_email_manageCoverage branch from ed5866c to 41a5836 Compare August 7, 2023 19:02
@williamjallen williamjallen enabled auto-merge August 7, 2023 19:11
@williamjallen williamjallen added this pull request to the merge queue Aug 7, 2023
Merged via the queue into master with commit e517097 Aug 7, 2023
@williamjallen williamjallen deleted the fix_500_error_email_manageCoverage branch August 7, 2023 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants