Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Store column values of not cache-able associations#1302

Merged
Ocramius merged 9 commits into
doctrine:masterfrom
goetas:pr1301
Mar 17, 2015
Merged

Store column values of not cache-able associations#1302
Ocramius merged 9 commits into
doctrine:masterfrom
goetas:pr1301

Conversation

@goetas
Copy link
Copy Markdown
Member

@goetas goetas commented Feb 11, 2015

Fixes #1301

@doctrinebot
Copy link
Copy Markdown

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DDC-3566

We use Jira to track the state of pull requests and the versions they got
included in.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

What if the entity is not in identity map?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

has it to be persisted somehow?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not an expert but I think some kind of proxy should be created to allow traversal of the association (that will obvisouly trigger another request).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

you are right! IdentifierFlattener is the answer (i hope)! I will try do do it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you try to remove this line and make sure the test still passes? From your code, it seems that you are trying to extract the identifier from the association, but if the association is not cached, then this means the cache does not hold any identifier for the association, right?

@bakura10
Copy link
Copy Markdown
Member

It would be nice if you could also add the same kind of tests but for ManyToOne associations, to make sure it also work properly when there is no @Cache on the association.

@goetas goetas changed the title Store column values of not cache-able associations [WIP] Store column values of not cache-able associations Feb 11, 2015
@goetas
Copy link
Copy Markdown
Member Author

goetas commented Feb 12, 2015

Done

@goetas goetas changed the title [WIP] Store column values of not cache-able associations Store column values of not cache-able associations Feb 12, 2015
@guilhermeblanco
Copy link
Copy Markdown
Member

@goetas at first this seems very good. I may have looked too quickly, but do you mind ensuring there's a & TO_ONE association with composite keys and check if it works as a test case?

@goetas
Copy link
Copy Markdown
Member Author

goetas commented Feb 12, 2015

I think that if I add a "good" association with multiple keys and nested association, the test will fail.

Any chance to see #1113 merged before this? The mentioned PR contains a lot of improvements for composite keys that will be helpful to create a good test for this PR.

@bakura10
Copy link
Copy Markdown
Member

@goetas did you try to run the test by commenting the line I've told in the comment?

@goetas
Copy link
Copy Markdown
Member Author

goetas commented Feb 13, 2015

@bakura10 you mean this right?

$this->assertNull($this->cache->getEntityCacheRegion(Client::CLASSNAME));
$this->assertInstanceOf('Doctrine\ORM\Cache\Region', $this->cache->getEntityCacheRegion(Token::CLASSNAME));

$client = new Client('FabioBatSilva');
$token  = new Token('token-hash', $client);

$this->_em->persist($client);
$this->_em->persist($token);
$this->_em->flush();
$this->_em->clear();

$queryCount = $this->getCurrentQueryCount();

$this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->getToken()));
$this->assertFalse($this->cache->containsEntity(Client::CLASSNAME, $client->getId()));

$entity = $token;
//$entity = $this->_em->find(Token::CLASSNAME, $token->getToken());

$this->assertInstanceOf(Token::CLASSNAME, $entity);
$this->assertInstanceOf(Client::CLASSNAME, $entity->getClient());
$this->assertEquals('token-hash', $entity->getToken());
$this->assertEquals($queryCount, $this->getCurrentQueryCount());

$this->assertEquals('FabioBatSilva', $entity->getClient()->getName());
$this->assertEquals($queryCount, $this->getCurrentQueryCount());
//$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());

With this, the test is green.

@bakura10
Copy link
Copy Markdown
Member

Nope, you need to uncomment the ->clear() call. Actually the use case is the following: in first request, the entity is put in cache, in next request, obviously no object is in identity map.

@goetas
Copy link
Copy Markdown
Member Author

goetas commented Feb 13, 2015

@bakura10 I have edited my previous comment. Even for this version, tests are green.

It it ok?

@bakura10
Copy link
Copy Markdown
Member

Yep, sounds nice :D.

@bakura10
Copy link
Copy Markdown
Member

I just do not understand what happen under the hood. It seems that you are retrieving the association from the id, but in the case, the id does not exist because it has not been put into the cache.

@goetas
Copy link
Copy Markdown
Member Author

goetas commented Feb 13, 2015

@bakura10 I've edited the buildCacheEntry method, this means that I'm putting data into cache, later, UoW::createEntity will be able to create the right entity.

@bakura10
Copy link
Copy Markdown
Member

But you are not supposed to put the id in cache if @Cache is not present in the association. For instance, if the client of the token is modified on the token, then you will retrieve an out-of-date association ID (or maybe Doctrine is smart enough to invalidate the cache whenever the entity is updated).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove all unnecessary API

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The addToken method is used to create easily the link between "action" and "token" instances

@goetas goetas changed the title Store column values of not cache-able associations [WIP] Store column values of not cache-able associations Feb 20, 2015
@goetas
Copy link
Copy Markdown
Member Author

goetas commented Feb 20, 2015

green :)

Even with foreign entities as keys
/cc @guilhermeblanco

@goetas
Copy link
Copy Markdown
Member Author

goetas commented Feb 24, 2015

@Ocramius I have updated the test suite

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@guilhermeblanco To be honest I'm not sure that this approach will work with nested composite keys & associations

@goetas goetas changed the title [WIP] Store column values of not cache-able associations Store column values of not cache-able associations Feb 24, 2015
@Ocramius Ocramius removed the WIP label Mar 17, 2015
Ocramius added a commit that referenced this pull request Mar 17, 2015
Store column values of not cache-able associations
@Ocramius Ocramius merged commit 1add0a0 into doctrine:master Mar 17, 2015
@Ocramius
Copy link
Copy Markdown
Member

👍

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.

6 participants