Skip to content

Conversation

@CarlSchwan
Copy link
Member

@CarlSchwan CarlSchwan commented Nov 17, 2025

Best to review commit by commit. The last two are automated

Summary

Expose multiple methods from result from doctrine:

  • fetchAssociative
  • fetchNumeric
  • fetchOne
  • fetchAllAssociate
  • fetchAllNumeric
  • fetchFirstColumn
  • iterateNumeric
  • iterateAssociate

Deprecated

  • fetch and fetchAll

A rector rule is also created to automate the transition nextcloud-libraries/rector#63

TODO

  • ...

Checklist

@CarlSchwan CarlSchwan added this to the Nextcloud 33 milestone Nov 17, 2025
@CarlSchwan CarlSchwan self-assigned this Nov 17, 2025
@CarlSchwan CarlSchwan changed the title Carl/result improv Improve IResult Nov 17, 2025
Copy link
Member

@provokateurin provokateurin left a comment

Choose a reason for hiding this comment

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

I don't get the purpose of iterateNumeric and iterateAssociative if they just call the fetch methods. Developers will probably think that this optimizes memory consumption by not loading all results at once, but this is not the case as far as I understand from this code.

@CarlSchwan CarlSchwan force-pushed the carl/result-improv branch 2 times, most recently from 5e5e43e to 6f5952e Compare November 18, 2025 13:37
- fetch is replaced with fetchAssociative/fetchNumeric/fetchOne with
  better type hinting
- Same with fetchAll
- And add iterateAssociative/iterateNumeric which are nicer to use than
  a `while ($row = $result->fetch()) {}`

Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
@CarlSchwan CarlSchwan marked this pull request as ready for review November 18, 2025 16:50
@CarlSchwan CarlSchwan requested review from ArtificialOwl and icewind1991 and removed request for a team November 18, 2025 16:50
@ChristophWurst ChristophWurst added the pending documentation This pull request needs an associated documentation update label Nov 19, 2025
Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

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

Very nice

This will impact a lot of app code, so thanks for the rector rule 🙏

There should also be documentation for app devs including examples given the impact.

@nickvergessen
Copy link
Member

nickvergessen commented Nov 19, 2025

Deprecated

  • fetch and fetchAll

Is this really needed? This, same as with execute(), will mean that every (select) query has to be touched again or you add hundreds of lines into your baseline or run rector which breaks backports.

I'd be in favor of making a note, and once we have few things we want to deprecate, we do them in one organized released, instead of each release bringing a single change and you need to touch each place all the time

Copy link
Contributor

@miaulalala miaulalala left a comment

Choose a reason for hiding this comment

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

Why deprecate fetch / fetchAll? Instead, leave that with the default associative and remove the fetch mode parameter. Leave those code changes where no other result type is used, and refactor those instances where a PDO::FETCH_NUMERIC is used to the new exposed method.

Benefits: no Psalm errors, no backport conflicts, marginal change in the interface

But still add a note that the new methods are preferred.

Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
@CarlSchwan
Copy link
Member Author

Why deprecate fetch / fetchAll? Instead, leave that with the default associative and remove the fetch mode parameter. Leave those code changes where no other result type is used, and refactor those instances where a PDO::FETCH_NUMERIC is used to the new exposed method.

Benefits: no Psalm errors, no backport conflicts, marginal change in the interface

I undeprecated fetch and fetchAll for now but we can't change the signature and behavior of these methods, otherwise it breaks a lot of stuff and we should avoid breaking changes.

@CarlSchwan
Copy link
Member Author

Documentation nextcloud/documentation#13866

Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
@blizzz
Copy link
Member

blizzz commented Nov 19, 2025

What also would be cool is a Result interface that does not take the complete result array, but the pointer to the DB result resource. And then it can truly traverse memory-efficiently through the result set. Could be beneficial for network saturation in some cases as well, maybe?

(Out of scope here)

@tobiasKaminsky tobiasKaminsky merged commit 6f0537b into master Nov 20, 2025
188 of 195 checks passed
@tobiasKaminsky tobiasKaminsky deleted the carl/result-improv branch November 20, 2025 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews pending documentation This pull request needs an associated documentation update technical debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants