-
-
Notifications
You must be signed in to change notification settings - Fork 453
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
Api Method "deleteItemsByTagsAll()" removes unrelated items #713
Comments
Hello, I don't have much time actually, can you give me a sample of code so I can test it quickly ? Cheers, |
Hi, Not by hand but I think your increment, or one of the other examples, fits. I see if I can make one out of it. Regards, |
Hmmm I think I know why we have this kind of behavior: Item A with tags "shared"
But B has also an additional tag: "custom" which is ignored, why ? Item A with tags "shared, shared2" If In a nutshell: When This strange behavior will be fixed as soon I can. |
I think that all |
@Geolim4 thanks for the feedback, sounds reasonable why it happened. I cannot confirm if this happens with all Have you seen the same behavior ? |
I can't test it right now, this is the reason I'm asking you more details :) |
I need to see if I can make an in-code test-case. Otherwise I can try to make one but I found this out in the heat of the moment as well so I keep this open and I try to test it out as well. If I'm right I need to create one, let me try to focus on that tomorrow. |
In fact I'm realizing that by fixing this not "well-documented" behavior, I would introduce a massive breaking change which would go against my SEMVER commitment. Instead I will add a new set of features in the next release of this summer called Sorry, I can't fix this now, as it's more a not "well-documented" behavior rather than a real bug by itself. The current behavior is:
Calling
Why ? Because "Deleting item By All Requested Tags", here 'shared'. No lets see what you describing/expecting: The behavior would be:
Calling
So what now ? |
See here the list of broken tests: I can not even "fix the tests" because this would implicitly shows that I'm introducing "incompatible breaking changes" in the middle of a minor/patch version, which is completely forbidden by SEMVER commitments. Q: Why am I so compliant with Semver commitment ? |
I'm not closing this bug and planned it as a feature for the V8 😄 Cheeres, |
Hi, Thank you for the explanation and work on this, I think we have some misunderstanding. What I see is: The current behavior is: Item1 has the following tags: shared, custom1 Item1 ===================================== The behavior would be: Item1 has the following tags: shared, custom1 Item1 has both tags specified in deleteItemsByTagsAll call: shared, custom1 Item 2 would have been removed when it was called with At some point I think I understand you but at the other side maybe you explain it wrong or we are both confused ? I hope this helps, I think it's a false positive "bug". Regards, |
Nah, this behavior is fine, I tested it yesterday, and it's being already unit-tested, see by yourself the following code: <?php
/**
* @author Khoa Bui (khoaofgod) <[email protected]> https://www.phpfastcache.com
* @author Georges.L (Geolim4) <[email protected]>
*/
use Phpfastcache\CacheManager;
use Phpfastcache\Drivers\Files\Config as FilesConfig;
use Phpfastcache\Helper\TestHelper;
chdir(__DIR__);
require_once __DIR__ . '/../../vendor/autoload.php';
$testHelper = new TestHelper('Github issue #713 - Api Method "deleteItemsByTagsAll()" removes unrelated items');
$cacheInstance = CacheManager::getInstance('Files', new FilesConfig(['securityKey' => 'test-713']));
$cacheInstance->clear();
$item1 = $cacheInstance->getItem('item1');
$item2 = $cacheInstance->getItem('item2');
$item1->addTags(['shared', 'custom1']);
$item1->set(1337);
$item2->addTags(['shared']);
$item2->set(1337);
$cacheInstance->saveMultiple($item1, $item2);
$cacheInstance->detachAllItems();
unset($item1, $item2);
$cacheInstance->deleteItemsByTagsAll(['shared', 'custom1']);
$item1 = $cacheInstance->getItem('item1');
$item2 = $cacheInstance->getItem('item2');
var_dump($item1->isHit());
var_dump($item2->isHit());
if ($item1->isHit()) {
$testHelper->printPassText('Item #1 is still in cache as expected.');
} else {
$testHelper->printFailText('Item #1 is no longer in cache and so has been unexpectedly removed.');
}
$testHelper->terminateTest(); Current Output:
As you can see, item1 has been removed while item2 still exists. |
(This is the test I had prepared before I realized that I would introduce a massive breaking change). |
In the behavior here I see all items going down to zero in my cache, which is strange. I need to investigate what goes wrong (here). It is still a good topic to discuss :) |
I think it might first be useful to have a better description of what the functions are supposed to do. The current documentation is a bit vague and awkwardly worded
As I understand their functionality they would be much better described with the following
Making it clear that deleteItemsByTags is functionally the same as foreach($tags as $tag){
$pool->deleteItemsByTag($tag)
} And that deleteItemsByTagsAll is functionally the same as foreach($pool->getItems() as $item){
foreach($tags as $tag){
if( !in_array($tag, $items->getTags() ){
continue 2;
}
$pool->deleteItem($item->getKey());
}
}
Atleast with my testing this seems to be the case. |
@wolfgangvc The README already describes this behavior but maybe not enough. |
Hello !! 🆕 in V8: Multiple strategies (
This has been implemented as of the API v3
Expect the V8 to be released by the summer 2020 :) Cheers, |
Sorry for my late response, but this is great! Is V8 already usable without being released ? Thanks a lot! |
Hello, nope it's still in development status, despite the tests are ok, I would not recommend it for use in a production environment ! I still have a bunch of docs & tests to made. |
Hi, I got mentioned by someone (that was involved here), maybe this is usable for this as well to make dev easier ? https://github.com/team-a-pro/collection |
See the discussion above :) |
I know but I meant if future development makes it easier why not switch instead ? Not that it's needed, if it saves time I would say... a refactor is never a bad learning curve :) |
Yes it does what you meant, because the tags now supports all possible use cases. It is implemented in V8 because it's not backward compatible and would break the SemVer. |
All the available strategies are interfaced here: |
Which is great! I though I just notice you when you want to be 'lazy' in the future :) |
When You add multiple items that have their own tag and also share a tag it seems that when you delete an item using
deleteItemsByTagsAll(['sharedTag', 'ownTag'])
that all items that share'sharedTag'
are also removed.Following the docs it should only remove items that have multiple tags or all you set for this function, not one or more like deleteItemsByTags() does.
This happens for me on Couchbase buckets.
To Reproduce
Steps to reproduce the behavior:
deleteItemsByTagsAll(['sharedTag', 'ownTag'])
So 10 items should be in total 21 => 10 items, 10 unique tags items, 1 shared tag item
Expected behavior
One item removed and one (unique) tag, so 2 items less in the bucket and the rest should stay
Current behavior
All items that share the shared tags are removed, so also are their individual tags.
The text was updated successfully, but these errors were encountered: