While implementing #2574611: Unify our two task systems I realized that we currently don't delete the items from the server when removing a datasource from an index – we just remove them from the tracking table.
This is of course a glaring bug we have to fix before beta.

We'll probably need an additional method on the server to faciliate this, as we'd otherwise have to retrieve all the IDs of the datasource first and pass them to deleteItems(). Either a new method, or just a new optional $datasource_id parameter for deleteAllIndexItems() – probably the latter.

Comments

drunken monkey created an issue. See original summary.

drunken monkey’s picture

Status: Active » Postponed
Related issues: +#2574611: Unify our two task systems
StatusFileSize
new18.04 KB

This patch demonstrates the bug. Won't apply yet, though, since it's based on #2574611: Unify our two task systems.

drunken monkey’s picture

This implements the necessary changes to fix the issue. I also found a flaw in the reaction to a changed tracker – this should now also be fixed.
To add tests for the tracker change, this is now also postponed on #2574589: Move the "remove unloadable items from tracking" logic to the index (which, in turn, is also postponed on #2574611: Unify our two task systems). But, as usual, setting to NR to get the test bot into action.
Please only look at the interdiff (and #2), though, as the other patches contain the whole of #2574611: Unify our two task systems, too.

One thing I'm unsure about is whether to add an optional parameter to deleteAllIndexItems() or to add a new method for it. I now went with the former option, since I believe it's the better, less confusing choice for the API, on the whole, but that's debatable, and both implementations in this project got considerably messier because of it. For Solr, on the other hand, this decision probably results in cleaner code than the other one.
So, input on that would be welcome (also on the rest of the patch, of course)!

Status: Needs review » Needs work

drunken monkey’s picture

Status: Needs work » Postponed

Huh. No idea what caused that, but let's just postpone again for now.

Status: Needs review » Needs work

drunken monkey’s picture

OK …
The code did have some errors in it, the attached patch completely passes for me locally.

Status: Needs review » Needs work

drunken monkey’s picture

Status: Needs work » Needs review
StatusFileSize
new370 bytes
new108.9 KB
drunken monkey’s picture

borisson_’s picture

Status: Needs review » Needs work

Only nitpicks here, this looks great!

  1. +++ b/search_api_db/tests/src/Kernel/BackendTest.php
    @@ -474,6 +474,20 @@ protected function checkModuleUninstall() {
    +      $this->assertFalse(\Drupal::database()
    +        ->schema()
    +        ->tableExists($field_table['table']), new FormattableMarkup('Field table %table exists', array('%table' => $field_table['table'])));
    

    I don't think we need the formattableMarkup here, we can just concatenate the string instead.

    However, this test looks great and is very readable, @drunken_monkey++

  2. +++ b/tests/src/Kernel/IndexChangesTest.php
    @@ -0,0 +1,312 @@
    +      // This comes from the test backend, which marks the index for re-indexing
    +      // every time it gets updated.
    

    I think we should move the comment out of the array.

drunken monkey’s picture

Agreed to both requests, patch attached.
Expanded the first part a bit to also include general cleanup of that method, since the new code had several flaws that were just copy/pasted (including the one you pointed out). Similar issues are in the rest of the class, too, but I didn't want to go completely out of scope.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

  • drunken monkey committed 83c6f83 on 8.x-1.x
    Issue #2730099 by drunken monkey: Fixed deletion of items from removed...
drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Great, thanks a lot for reviewing! (Forgot that in #20, sorry!)
Committed.

mkalkbrenner’s picture

Would have been keen to inform other backend maintainers about upcoming interface changes.
I didn't follow this issue :-(

#2737229: Fatal error: Declaration of SearchApiSolrBackend::deleteAllIndexItems() must be compatible

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.