Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Delete old search entry if new URL is more canonical #8647

Merged
merged 5 commits into from
Mar 16, 2017

Conversation

ausi
Copy link
Member

@ausi ausi commented Feb 17, 2017

Fixes #8498, #8460

@leofeyer leofeyer added this to the 3.5.25 milestone Feb 17, 2017
Copy link
Member

@aschempp aschempp left a comment

Choose a reason for hiding this comment

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

Instead of deleting and adding a new record, how about updating the URL so the existing entry is re-used?

@leofeyer leofeyer changed the base branch from master to hotfix/3.5.25 February 17, 2017 13:44
@ausi
Copy link
Member Author

ausi commented Feb 17, 2017

Instead of deleting and adding a new record, how about updating the URL so the existing entry is re-used?

A new record is not always created, this depends on the if ($objIndex->numRows) on line 208. So I think deleting the record should be OK, otherwise the logic gets more complicated.

@leofeyer
Copy link
Member

leofeyer commented Feb 17, 2017

That's not entirely true. We could run:

$db
    ->prepare('UPDATE tl_search SET url=? WHERE id=?')
    ->execute($arrSet['url'], $objIndex->id)
;

Then the query in line 201 would find the existing record.

Copy link
Member

@leofeyer leofeyer left a comment

Choose a reason for hiding this comment

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

If we really want to delete the existing record, we must also remove the child records from tl_search_index.

@ausi
Copy link
Member Author

ausi commented Feb 17, 2017

That's not entirely true. We could run:

$db
    ->prepare('UPDATE tl_search SET url=? WHERE id=?')
    ->execute($arrSet['url'], $objIndex->id)
;

Then the query in line 201 would find the existing record.

I don’t think so. This would result in a Query error: Duplicate entry '...' for key 'url' (UPDATE tl_search... error. See the reproducing steps from #8498 (comment)

@ausi
Copy link
Member Author

ausi commented Feb 17, 2017

If we really want to delete the existing record, we must also remove the child records from tl_search_index.

Addressed in fb40870

@leofeyer
Copy link
Member

I don’t think so. This would result in a Query error: Duplicate entry '...' for key 'url' (UPDATE tl_search... error.

You are right, of course.

@aschempp
Copy link
Member

aschempp commented Feb 17, 2017 via email

@ausi
Copy link
Member Author

ausi commented Feb 17, 2017

Because an entry with the new URL might already exist and the URL column has an unique index. I tried it out and got the Duplicate entry '...' for key 'url' error...

@aschempp
Copy link
Member

I don't understand that.

  1. we are searching for a database record by checksum
  2. if that record exists, we must delete it and not modify the URL, because the URL could exist
  3. then we create a record with that URL?

@fritzmg
Copy link
Contributor

fritzmg commented Feb 18, 2017

@aschempp see codefog/contao-cookiebar#21 (comment) for an example. The same page could be present multiple times in the tl_search table, with different GET parameters and different checksums. If you try to update the URL for one particular checksum, you might have duplicate URLs.

@aschempp
Copy link
Member

aschempp commented Feb 18, 2017 via email

@ausi
Copy link
Member Author

ausi commented Feb 19, 2017

I do understand that, but how can this be an issue if we add a new database record with exactly that URL and checksum just a few code lines later?

A few lines later there is a check if an entry with that URL already exists. Only if it doesn’t exist a new record is created, otherwise the existing record gets updated. And this record doesn’t have the same URL as the record we have deleted.

@leofeyer leofeyer merged commit 3fd37e3 into contao:hotfix/3.5.25 Mar 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants