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
CB-263: Update publication date of draft reviews on CritiqueBrainz when they get published #171
Conversation
Can one of the admins verify this patch? |
1 similar comment
Can one of the admins verify this patch? |
critiquebrainz/db/review.py
Outdated
@@ -322,7 +334,7 @@ def list_reviews(*, inc_drafts=False, inc_hidden=False, entity_id=None, | |||
offset=None): | |||
"""Get a list of reviews. | |||
|
|||
This function provides several filters that can be used to select a subset of reviews. | |||
This function provides several filters that can be used to select a subset of reviews. |
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.
Hi, it seems a space was added here by mistake
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.
oh, yeah, you're right, I'll remove that right away
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.
sorry about making more problems with one of the commits; I'm on a school computer and not having fun using the in-browser editor
admin/sql/create_tables.sql
Outdated
is_hidden BOOLEAN NOT NULL, | ||
license_id VARCHAR NOT NULL, | ||
language VARCHAR(3) NOT NULL, | ||
publish_time TIMESTAMP, |
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.
Let us make that publish_date
to be more clear. :)
critiquebrainz/db/review.py
Outdated
@@ -83,6 +84,7 @@ def get_by_id(review_id): | |||
review.language, | |||
review.source, | |||
review.source_url, | |||
review.publish_time, |
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.
Since we are adding another column to the table (for publish date), it is important to remove the subquery for creating created_time
and the corresponding entry of created_time.created
in SELECT
, as that part is now unnecessary.
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.
Also, for adding the Last Revised:
information, you can make use of the revision.timestamp
, so I would suggest it to rename the column as last_revision_timestamp
.
critiquebrainz/db/review.py
Outdated
@@ -220,6 +222,10 @@ def update(review_id, *, drafted, text=None, rating=None, license_id=None, langu | |||
if is_draft is not None: | |||
if not drafted and is_draft: # If trying to convert published review into draft | |||
raise db_exceptions.BadDataException("Converting published reviews back to drafts is not allowed.") | |||
if drafted and (not is_draft): |
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.
I think there is no need of the parentheses.
if drafted and not is draft:
...
@IsaacZanoria Since it is a |
@IsaacZanoria There are more changes to be made for this PR to be merged:
|
@brainzbot test this please |
@IsaacZanoria See the Jenkins errors to fix the tests ( |
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.
You also need to update the function db.review.list_reviews
and handle cases where published_on
can be Null
.
@@ -0,0 +1,5 @@ | |||
BEGIN; | |||
|
|||
ALTER TABLE review ADD COLUMN published_on TIMESTAMP; |
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.
There is no need of the BEGIN
and COMMIT
statements here.
@@ -1,6 +1,7 @@ | |||
import critiquebrainz.db.avg_rating as db_avg_rating | |||
import critiquebrainz.db.exceptions as db_exceptions | |||
|
|||
|
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.
This is unnecessary. :)
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.
sorry, ive seen a pep8 warning about "2 blank lines expected" in tests, and figured i'd just fix it
critiquebrainz/db/review_test.py
Outdated
@@ -196,7 +196,7 @@ def test_list_reviews(self): | |||
self.assertEqual(count, 1) | |||
self.assertEqual(len(reviews), 1) | |||
|
|||
reviews, count = db_review.list_reviews(sort="created") | |||
reviews, count = db_review.list_reviews(sort="") |
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.
I think you should put published_on
as an argument here. This would test if the reviews are fetched successfully if ordered by publish date.
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.
sorry, i already have the "published_on" argument set up, i think i was in the middle of adding it here and got distracted, and ended up leaving it blank
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.
No problem :)
@@ -93,23 +94,12 @@ def get_by_id(review_id): | |||
"user".show_gravatar, | |||
"user".musicbrainz_id, | |||
"user".is_blocked, | |||
created_time.created, | |||
license.full_name, | |||
license.info_url | |||
FROM review | |||
JOIN revision ON revision.review_id = review.id | |||
JOIN "user" ON "user".id = review.user_id | |||
JOIN license ON license.id = license_id |
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.
Please make sure that the query is right. I see that the WHERE
clause is now missing. You can fix the query by adding a WHERE
clause for the review_id
. :)
I think there is a bug in |
Don't worry about the Also, just saw your query on IRC regarding sorting on |
The update script that accompanies this should also fill out the correct values in the new column added for all existing rows. |
@@ -0,0 +1 @@ | |||
ALTER TABLE review ADD COLUMN published_on TIMESTAMP; |
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.
We'd also want to fill up the published_on
column with values for old reviews.
And this should be inside a transaction.
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.
add new column (publish_time) to review table which is only updated when a review is published without saving as a draft or changed from a draft to a published review. add to get_by_id() so that it gets put in the returned dictionary, and change html tempaltes to use the value from the new key
…ted_time.created from db.review
…A_VERSION value also remove that "expect 2 blank lines" error PEP8 keeps on getting in views.test
all the other files had it, so i thought i'd be safe
test now sorts by new "published_on" column
Also, show both created date and published on date on user review page.
@brainzbot add to whitelist |
@ferbncode, this is ready for review, would you mind taking a look at the last two commits I made? |
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.
OK to go for me.
🥇
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.
LGTM 👍
add new column (publish_time) to review table which is only updated when a review is published without saving as a draft or changed from a draft to a published review. add to get_by_id() so that it gets put in the returned dictionary, and change html tempaltes to use the value from the new key