-
Notifications
You must be signed in to change notification settings - Fork 190
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
Split binary to booleans #203
Conversation
I was already working on it (assigned it to myself), got about as far as you did :) if you want to work on it further, i can look at some of the other bugs (if Bernhard hasn't fixed them all before that :).
Bernhard pointed me to the docs for migration, its 'repair-steps' in info.cml iirc. At work now, don't have this info at hand.
…On 11 July 2017 00:29:58 CEST, Daniel Opitz ***@***.***> wrote:
Since no one wrote on #191 I tried myself to map the status to boolean
types. I already changed the code to use the new boolean fields instead
of the status.
I don't really know what to do with StatusFlag::typeToStatus - if we
should completely remove this one and somehow fix the code belongs to
this, or move this to later and destruct this status in ItemMapper (see
added comment). This would also change methods signatures for many
methods.
I didn't find a way how we could add a data migraion from status to the
new boolean fields, I just found asome [docs in
OC](https://doc.owncloud.org/server/10.0/developer_manual/app/schema.html)
but it looks like in [NC we don't have this
feature](https://docs.nextcloud.com/server/12.0/developer_manual/app/schema.html)
- so how should we migrate?
I'm submitting this for the questions and also for a first review.
Todo
---
- [ ] Fix tests
- [ ] Migration script
- [ ] Completely remove status or map on some code parts?
You can view, comment on, or merge this pull request online at:
#203
-- Commit Summary --
* replaced old status with 2 flags for unread and starred
-- File Changes --
M lib/Db/FeedMapper.php (12)
M lib/Db/Item.php (53)
M lib/Db/ItemMapper.php (49)
M lib/Db/Mysql/ItemMapper.php (21)
M lib/Fetcher/FeedFetcher.php (2)
M lib/Service/ItemService.php (9)
-- Patch Links --
https://github.com/nextcloud/news/pull/203.patch
https://github.com/nextcloud/news/pull/203.diff
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
#203
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
Looks like we basically did the same things, except I used true/false in sql where you used 1/0. I tend to prefer true/false. Anyway, if you want to continue to work on it that would be very welcome! I started to investigate 'repair-steps' (see http://nextcloudappstore.readthedocs.io/en/latest/developer.html#info-xml), which seems the way to go re migration. As for the typeToStatus, I figure we should remove it and refactor code that is currently using it. It feels the typeToStatus method is a bit of a kludge.. Thanks for working on this! Let me know if you decide to drop it afterall. I will pause my work on this one for now in favour of some other bug(s). |
Oh sry didn't see you assigned yourself. Indeed True/False are the better option for this. I will keep working on this until someone stops me from doing this :) |
BTW since you are changing SQL statements it might make sense to throw away the unit tests and replace them with integration tests (examples available in the test folder) |
I dropped the unit tests which belongs to the changed mappers and added integration tests. Also I added the repair step which checks for previous installed version. Currently I increased the version by a patch level, I think an increase in minor/major would be better? |
For me it's ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work, everything looks like expected although I didn't have the power to make sure that the code still does the same thing in all places. I don't fully understand the bool casts however.
lib/Db/Item.php
Outdated
$this->status |= StatusFlag::UNREAD; | ||
public function setUnread($value = true) { | ||
$this->markFieldUpdated('unread'); | ||
$this->unread = (bool)$value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we need bool casts?
I'd take a look at the MySql version on travis. Does it work for you locally on mysql? |
Yep. I'm unsure if the doctrince DAL handles the conversion for you or it could be solved via query builder. Worst case scenario is that we need to create a method that turns bools into whatever format your db currently expects. Check https://github.com/nextcloud/news/blob/master/lib/Db/MapperFactory.php#L23 for how to find out the db |
|
Can you take care of the tests? |
Didn't notice the tests fail again, maybe this was the reason for bool casts. I'll have a look. |
It's green 😁 |
Cool, just a quick question: Can you set up a news install without the pull request, add some feeds and star them, then switch to your branch and ensure that everything still works as expected? Just trying to make sure that everything still works since the PR is quite big. |
From a quick glance over the code the only thing that I don't really like is the usage of empty(). That "function" is pretty tricky and can lead to lots of bugs, see http://php.net/manual/en/function.empty.php |
Do you have another idea how to have another way to force booleans? I have in mind that empty checks are faster than bool casts. And without such cast the one unit test was failing. Maybe the problem comes from another place but don't know right now. |
There still is an issue in the migration where status 6 results in unread=false. I didn't find a proper solution yet.. |
…ved StatusFlags class + refactor code relying to it
…ite doesn't support true/false
PHP is slow anyways so don't worry about speed of function calls but speed of algorithmic complexity ;) Also better to investigate the source of the issue There still is an issue in the migration where status 6 results in unread=false. I didn't find a proper solution yet..
Are we sure that all three dbs treat this as truthy?
I'd expect something like
|
Tested it on MySQL and SQLite - it was working for me.
I dropped usage of the QueryBuilder in favor of a native SQL query in the migration step. Now I'm also using
I will have a deeper look. |
@BernhardPosselt I changed something in my last commit to remove bool casts and empty checks. |
Ok, reviewed it more closely and lets test it out, as in: merge this and check the effects on our own instances :D |
Seems to have worked fine on postgres, well done :) let's give this more testing before we create a release |
Since no one wrote on #191 I tried myself to map the status to boolean types. I already changed the code to use the new boolean fields instead of the status.
I don't really know what to do with StatusFlag::typeToStatus - if we should completely remove this one and somehow fix the code belongs to this, or move this to later and destruct this status in ItemMapper (see added comment). This would also change methods signatures for many methods.
I didn't find a way how we could add a data migraion from status to the new boolean fields, I just found asome docs in OC but it looks like in NC we don't have this feature - so how should we migrate?
I'm submitting this for the questions and also for a first review.
Todo