-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix update to remove shares where file doesn't exist on postgres #7293
Conversation
makes sense 👍 |
I added the unit test. Ready to review and merge. cc @PVince81 @schiesbn |
code looks good, I also executed the test successfully on my local sqlite... Let's wait for Jenkins tests with the other databases... otherwise 👍 |
@PVince81 It's broken, because previous tests doesn't clean up the database :( @DeepDiver1975 Should I just clear the tables in "setup" or should I try to find the cause of the data? |
yes - that's acceptable - thx |
Test_Files_Sharing_Updater::testRemoveBrokenShares Column definition: https://github.com/owncloud/core/blob/master/db_structure.xml#L840
|
Maybe the field backticks are missing. I'll see if I can fix it, I can run the test against the Stuttgart Oracle instance. |
@MorrisJobke I've fixed the backticks, the tests can now run on Oracle (they did locally).
|
💣 Test Failed. 💣 |
@PVince81 Seems to be related to a misinterpreted SQL statement on oracle. Is anybody here who can try the actual SQL statement on oracle? I don't have an oracle DB here. Steps to do:
cc @butonic |
The deletion worked but it seems to be the one with fileid=3 that was deleted, not 2. |
@MorrisJobke can you change the code and make it "id proof" ? Maybe put a name in "item_target" and select on the string instead of the id when checking whether it was deleted correctly. |
@MorrisJobke the query runs fine: SELECT "oc_share"."id"
FROM "oc_share" LEFT JOIN "oc_filecache" ON "file_source" = "oc_filecache"."fileid"
WHERE "oc_filecache"."fileid" IS NULL AND "oc_share"."item_type" IN ('file', 'folder');
id
----------
34 Instead of first querying the database for all shares on files that don't exist and then deleting every obsolete share individually, you should let the database handle all of it: DELETE FROM "oc_share" WHERE "file_source" NOT IN (
SELECT "fileid" FROM "oc_filecache" WHERE "item_type" IN ('file','folder')
); Everything executed in one query to the DB. |
I think at some point @bantu mentionned that we can't use subqueries ? (might have been something else) |
also keep in mind that we are talking about a update script. This gets executed exactly once for every user. I don't think this need to be highly optimized, let's take the safe way. |
@PVince81 Yes, on mysql there is a problem with modifying a table when you already used it in a subselect: http://stackoverflow.com/a/12969601. The workaround is tu use a virtual table as I did in search_lucene. Anyway, that workaround is not necessary in this case. @schiesbn If you consider going through the php stack - with all it's typelessness - safer ... ;) Also, users with millions of files tend to complain when migration takes ages. Ask @felixboehm for details. Which is why I prefer letting the database handle it natively and if necessary take spacial care of mysql as in search_lucene. |
@butonic I will give your subselect idea a try and jenkins will show us the problems, right? |
We've been down this road before with this very patch. See: #6016 Tests passed with the sub-query, but instead of committing the patch, a request was made to do it over again without the subquery. |
@jmcclelland Sorry for that back and forth. I just checked the PR and the subquery there contains a needless JOIN and this one here is covered by an unit test, which hopefully covers the relevant cases. Maybe we can find together the correct solution. :) |
@karlitschek Your opinion? |
Let's go with the simple approach. Performance is not important in this case. |
@owncloud-bot retest this please |
@MorrisJobke looks like now all the shares were deleted ? |
@PVince81 It's weird... will have another try tomorrow |
Any update ? |
@MorrisJobke did you have any luck with the VM ? |
@PVince81 Not yet ... internet connection is sort of unstable and resume doesn't work 😕 |
@MorrisJobke I've discovered that Oracle ignores the ids you give for primary keys, I had this in another PR. Maybe that's what's happening here. |
Better use \OC_DB::insertId('PREFIX'table') after the INSERT to retrieve whichever id Oracle decided to give instead of yours. |
Seems it's the mapping between filecache entries and share entries might be wrong because of that generated id issue. I'll give it a try. |
Now using \OC_DB::insertId() to retrieve the generated ids because Oracle ignores the passed values.
Here you go, it should work now. |
A new inspection was created. |
@owncloud-bot retest this please |
Something was wrong with the tests and the wrong ids were used. I'm surprised that the tests still passed locally. "Fortunately" Oracle has spotted these... Now let's hope that they pass on Jenkins! |
The inspection completed: 34 new issues, 33 updated code elements |
🚀 Test Passed. 🚀 |
The code has been changed since the last review, so please re-review |
@MorrisJobke @jmcclelland @schiesbn can you please review @PVince81’s new changes? |
Also cc'ing @julienfastre for review because you commented on the previous pull request #6016 |
👍 Works My steps (for SQLite): (
Checkout this branch and load your ownCloud instance to update the app.
|
Ok, that should be enough, merging now. |
fix update to remove shares where file doesn't exist on postgres
@PVince81 Awesome ...it gets into master \o/ |
This is just a cherry pick of the changes from #6016 to be able to add unit tests to this PR.
credit for the fix goes to @jmcclelland