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

Refactor cursor classes to compose CursorInterface #1206

Merged
merged 5 commits into from
Aug 18, 2015

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Aug 17, 2015

Fixes #1018, Closes #639.

This change refactors the Cursor class to no longer extend Doctrine\MongoDB\Cursor and instead implement the new cursor interface.
Currently tests are failing due to an issue with complex id types and toArray functionality, this can be fixed by always defining useKeys = false for eager cursors after doctrine/mongodb#223 has been merged.

Composing CursorInterface instead of the base cursor class also allows us to deprecate the ODM\EagerCursor class since the special handling related to eager cursors is done by doctrine/mongodb and does not need any special handling.

This also fixes a long-standing issue (#520) where using reference priming in combination with getSingleResult would still prime references for the entire dataset, not only the one document being fetched from the cursor.

Last but not least, this introduces ~1.2 as new version requirement for doctrine/mongodb and removes special treatment for eager cursors in DocumentPersister.

Note: since a few methods are still missing (see doctrine/mongodb#225) and there is no stable release of doctrine/mongodb containing the interface yet, this branch temporarily uses a dev version of doctrine/mongodb.

* @param ReferencePrimer $referencePrimer
* @return self
*/
public function enableReferencePriming(array $primers, ReferencePrimer $referencePrimer)
Copy link
Member

Choose a reason for hiding this comment

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

As discussed in video chat, let's have this method (and primeReferences()) assert that the wrapped cursor is eager. If not, we can throw an exception.

This addresses the manual case of users creating their own ODM Cursor, since the query builder should not allow this anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, enableReferencePriming now throws a BadMethodCallException if the wrapped cursor is not an EagerCursor.

@alcaeus alcaeus force-pushed the eagercursor-deprecation branch from 264d024 to db0fa7a Compare August 17, 2015 20:32
@alcaeus alcaeus changed the title [WIP] Refactor cursor classes to compose CursorInterface Refactor cursor classes to compose CursorInterface Aug 17, 2015
@alcaeus alcaeus changed the title Refactor cursor classes to compose CursorInterface [WIP] Refactor cursor classes to compose CursorInterface Aug 17, 2015
@@ -319,6 +387,19 @@ public function hydrate($hydrate = true)
}

/**
* @param array $document
* @return object
Copy link
Member

Choose a reason for hiding this comment

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

This seem to return array|object|null as for instance getSingleResult()?

@alcaeus alcaeus force-pushed the eagercursor-deprecation branch from db0fa7a to 6681db4 Compare August 18, 2015 05:16
@alcaeus alcaeus added this to the 1.0.0 milestone Aug 18, 2015
@alcaeus alcaeus force-pushed the eagercursor-deprecation branch 2 times, most recently from 39fd3fc to d3768c6 Compare August 18, 2015 13:14
@alcaeus alcaeus changed the title [WIP] Refactor cursor classes to compose CursorInterface Refactor cursor classes to compose CursorInterface Aug 18, 2015
@@ -207,6 +218,20 @@ public function batchSize($num)
}

/**
* Wrapper method for MongoCursor::count().
*
* @see \Doctrine\MongoDB\Cursor::count()
Copy link
Member

Choose a reason for hiding this comment

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

Would it make more sense for these @see lines to point to the CursorInterface? I believe that also has doc-blocks, and then you could also do without the full namespace prefix, too (since the class name isn't ambiguous).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, definitely. Will change the docblocks accordingly.

@alcaeus alcaeus force-pushed the eagercursor-deprecation branch from d3768c6 to ec5e37c Compare August 18, 2015 14:45
/**
* EagerCursor wraps a Cursor instance and fetches all of its results upon
* initialization.
*
* @since 1.0
* @author Jonathan H. Wage <[email protected]>
* @deprecated Deprecated in favor of using Cursor
Copy link
Member

Choose a reason for hiding this comment

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

Can we append "; will be removed in 2.0"? (done for other @deprecated lines).

Andreas Braun added 3 commits August 18, 2015 17:10
This deprecates the EagerCursor class since its main goal is already handled by
Doctrine\MongoDB\EagerCursor. This also allows us to fix a long-standing issue
where calling getSingleResult() on a query with reference priming enabled would
prime references for the entire dataset.
@alcaeus alcaeus force-pushed the eagercursor-deprecation branch from ec5e37c to 6f13cf4 Compare August 18, 2015 15:10
@jmikola
Copy link
Member

jmikola commented Aug 18, 2015

LGTM.

@malarzm
Copy link
Member

malarzm commented Aug 18, 2015

malarzm added a commit that referenced this pull request Aug 18, 2015
Refactor cursor classes to compose CursorInterface
@malarzm malarzm merged commit 2e0afa2 into master Aug 18, 2015
@malarzm malarzm deleted the eagercursor-deprecation branch November 9, 2015 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getFirstResult nulls Cursor's Limit ODM Cursor should only compose, not extend, base Cursor class
3 participants