Skip to content

Commit

Permalink
Merge pull request #1476 from malarzm/remove-require-indexes
Browse files Browse the repository at this point in the history
[2.0] Remove requireIndexes and stuff thereto related
  • Loading branch information
malarzm authored Aug 5, 2016
2 parents d477eb4 + eafa7f4 commit 16679a0
Show file tree
Hide file tree
Showing 17 changed files with 15 additions and 788 deletions.
9 changes: 1 addition & 8 deletions docs/en/reference/annotations-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,6 @@ Optional attributes:
repositoryClass - Specifies a custom repository class to use.
-
indexes - Specifies an array of indexes for this document.
-
requireIndexes - Specifies whether or not queries for this document should
require indexes by default. This may also be specified per query.
-
writeConcern - Specifies the write concern for this document that overwrites
the default write concern specified in the configuration. It does not overwrite
Expand All @@ -415,18 +412,14 @@ Optional attributes:
* repositoryClass="MyProject\UserRepository",
* indexes={
* @Index(keys={"username"="desc"}, options={"unique"=true})
* },
* requireIndexes=true
* }
* )
*/
class User
{
//...
}
.. note::
Requiring Indexes was deprecated in 1.2 and will be removed in 2.0.

@EmbedMany
----------

Expand Down
108 changes: 0 additions & 108 deletions docs/en/reference/indexes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -439,111 +439,3 @@ index.
Partial indexes are only available with MongoDB 3.2 or newer. For more
information on partial filter expressions, read the
`official MongoDB documentation <https://docs.mongodb.com/manual/core/index-partial/>`_.

Requiring Indexes
-----------------

.. note::
Requiring Indexes was deprecated in 1.2 and will be removed in 2.0.

Sometimes you may want to require indexes for all your queries to ensure you don't let stray unindexed queries
make it to the database and cause performance problems.


.. configuration-block::

.. code-block:: php
<?php
/**
* @Document(requireIndexes=true)
*/
class Place
{
/** @Id */
public $id;
/** @Field(type="string") @Index */
public $city;
}
.. code-block:: xml
// Documents.Place.dcm.xml
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mongo-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/orm/doctrine-mongo-mapping.xsd">
<document name="Documents\Place" require-indexes="true">
<field fieldName="id" id="true" />
<field fieldName="city" type="string" />
<indexes>
<index>
<key name="city">
</index>
</indexes>
</document>
</doctrine-mongo-mapping>
.. code-block:: yaml
# Documents.Place.dcm.yml
Documents\Place:
fields:
id:
id: true
city:
type: string
indexes:
index1:
keys:
city: asc
When you run queries it will check that it is indexed and throw an exception if it is not indexed:

.. code-block:: php
<?php
$qb = $dm->createQueryBuilder('Documents\Place')
->field('city')->equals('Nashville');
$query = $qb->getQuery();
$places = $query->execute();
When you execute the query it will throw an exception if `city` was not indexed in the database. You can control
whether or not an exception will be thrown by using the `requireIndexes()` method:

.. code-block:: php
<?php
$qb->requireIndexes(false);
You can also check if the query is indexed and with the `isIndexed()` method and use it to display your
own notification when a query is unindexed:

.. code-block:: php
<?php
$query = $qb->getQuery();
if (!$query->isIndexed()) {
$notifier->addError('Cannot execute queries that are not indexed.');
}
If you don't want to require indexes for all queries you can set leave `requireIndexes` as false and control
it on a per query basis:

.. code-block:: php
<?php
$qb->requireIndexes(true);
$query = $qb->getQuery();
$results = $query->execute();
1 change: 0 additions & 1 deletion doctrine-mongo-mapping.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<xs:attribute name="repository-class" type="xs:string"/>
<xs:attribute name="inheritance-type" type="odm:inheritance-type"/>
<xs:attribute name="change-tracking-policy" type="odm:change-tracking-policy" />
<xs:attribute name="require-indexes" type="xs:boolean" />
<xs:attribute name="slave-okay" type="xs:boolean" />
</xs:complexType>

Expand Down
2 changes: 0 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ final class Document extends AbstractDocument
public $collection;
public $repositoryClass;
public $indexes = array();
/** @deprecated */
public $requireIndexes = false;
public $shardKey;
public $slaveOkay;
public $writeConcern;
Expand Down
19 changes: 0 additions & 19 deletions lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,6 @@ class ClassMetadataInfo implements \Doctrine\Common\Persistence\Mapping\ClassMet
*/
public $shardKey;

/**
* READ-ONLY: Whether or not queries on this document should require indexes.
*
* @deprecated property was deprecated in 1.2 and will be removed in 2.0
*/
public $requireIndexes = false;

/**
* READ-ONLY: The name of the document class.
*/
Expand Down Expand Up @@ -805,18 +798,6 @@ public function addIndex($keys, array $options = array())
);
}

/**
* Set whether or not queries on this document should require indexes.
*
* @param bool $requireIndexes
*
* @deprecated method was deprecated in 1.2 and will be removed in 2.0
*/
public function setRequireIndexes($requireIndexes)
{
$this->requireIndexes = $requireIndexes;
}

/**
* Returns the array of indexes for this Document.
*
Expand Down
3 changes: 0 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ public function loadMetadataForClass($className, ClassMetadata $class)
$this->addIndex($class, $index);
}
}
if (isset($documentAnnot->requireIndexes)) {
$class->setRequireIndexes($documentAnnot->requireIndexes);
}
if (isset($documentAnnot->slaveOkay)) {
$class->setSlaveOkay($documentAnnot->slaveOkay);
}
Expand Down
3 changes: 0 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ public function loadMetadataForClass($className, ClassMetadata $class)
if (isset($xmlRoot->{'shard-key'})) {
$this->setShardKey($class, $xmlRoot->{'shard-key'}[0]);
}
if (isset($xmlRoot['require-indexes'])) {
$class->setRequireIndexes('true' === (string) $xmlRoot['require-indexes']);
}
if (isset($xmlRoot['slave-okay'])) {
$class->setSlaveOkay('true' === (string) $xmlRoot['slave-okay']);
}
Expand Down
3 changes: 0 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Mapping/Driver/YamlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ public function loadMetadataForClass($className, ClassMetadata $class)
if (isset($element['changeTrackingPolicy'])) {
$class->setChangeTrackingPolicy(constant(MappingClassMetadata::class . '::CHANGETRACKING_' . strtoupper($element['changeTrackingPolicy'])));
}
if (isset($element['requireIndexes'])) {
$class->setRequireIndexes($element['requireIndexes']);
}
if (isset($element['slaveOkay'])) {
$class->setSlaveOkay($element['slaveOkay']);
}
Expand Down
15 changes: 0 additions & 15 deletions lib/Doctrine/ODM/MongoDB/MongoDBException.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,6 @@ public static function cannotPersistMappedSuperclass($className)
return new self('Cannot persist an embedded document or mapped superclass ' . $className);
}

/**
* @param string $className
* @param string $unindexedFields
* @return MongoDBException
*
* @deprecated method was deprecated in 1.2 and will be removed in 2.0
*/
public static function queryNotIndexed($className, $unindexedFields)
{
return new self(sprintf('Cannot execute unindexed queries on %s. Unindexed fields: %s',
$className,
implode(', ', $unindexedFields)
));
}

/**
* @param string $className
* @return MongoDBException
Expand Down
22 changes: 0 additions & 22 deletions lib/Doctrine/ODM/MongoDB/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ class Builder extends \Doctrine\MongoDB\Query\Builder
*/
private $primers = array();

/**
* Whether or not to require indexes.
*
* @var bool
*/
private $requireIndexes;

/**
* Whether or not to register documents in UnitOfWork.
*
Expand All @@ -102,20 +95,6 @@ public function __construct(DocumentManager $dm, $documentName = null)
}
}

/**
* Set whether or not to require indexes.
*
* @param bool $requireIndexes
* @return $this
*
* @deprecated method was deprecated in 1.2 and will be removed in 2.0
*/
public function requireIndexes($requireIndexes = true)
{
$this->requireIndexes = $requireIndexes;
return $this;
}

/**
* Set the current field to operate on.
*
Expand Down Expand Up @@ -377,7 +356,6 @@ public function getQuery(array $options = array())
$this->hydrate,
$this->refresh,
$this->primers,
$this->requireIndexes,
$this->readOnly
);
}
Expand Down
96 changes: 0 additions & 96 deletions lib/Doctrine/ODM/MongoDB/Query/FieldExtractor.php

This file was deleted.

Loading

0 comments on commit 16679a0

Please sign in to comment.