Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
comment.module
Priority:
Normal
Category:
Task
Assigned:
Issue tags:
Reporter:
Created:
30 Sep 2013 at 13:47 UTC
Updated:
29 Jul 2014 at 22:59 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
larowlanMakes sense
Comment #2
larowlanworking on this
Comment #3
larowlanFirst crack.
Adds an interface.
Not sure what to do with forum and tracker that query it direct.
Best I could muster would be some sort of queryAddCommentStatistics method that takes a query object, an array of fields, an array of joins and an array of expressions.
But that sounds really hacky, we have a query alter engine for just that already.
Thoughts?
Comment #5
larowlanentity type changes went in
Comment #7
larowlanyeah select() != insert()
Comment #9
larowlanmeh
Comment #10
andypost@larowlan Awesome start!
read/write/delete makes sense.
Suppose initializeRecord() should check for comment fields and throw exception when no comment fields found.
s/maximumCount/getMaximumCount
Looks unfinished because defines the query so would be queried directly
Comment #11
larowlanwhat about write -> updated
initializeRecord -> create
then we have CRUD, consistent
2. Agreed
3. But the service can be swapped, this is the closest thing to a service implementing a hook we have at the moment
Comment #12
larowlanWe already ignore non-existant fields in the initializeRecord (now ::create) method
Comment #13
jibranSeems alright. We can add some awesome unit tests
Comment #14
andypostNot sure about unit tests for that class because comment module have a lot web-tests that covers this functionality so the issue is about conversion.
Unit tests could be done in follow-up to unblock the #148849: Refactor {comment_entity_statistics} into performant Field
The ranking hook still questionable for me, I really dislike the way to provide a query crumbs via hook but this out of scope.
Comment #15
jhodgdonJust a note about hook_ranking... This is an ancient hook for Node Search that allows modules to say "This is a way of ranking node search results".
The hook is invoked at configuration time to find the name of the module's ranking(s) (in this case, the ranking is by number of comments on the node), and then at search time, to figure out what to join to the search query in order to rank result nodes by number of comments.
The core NodeSearch plugin for searching nodes does use a SQL query to do the search, so it needs to be able to join to a table of some sort in order to rank nodes by number of comments. We don't have an issue at this time in the Search module to redo how rankings are done (convert from a hook to plugins or something like that)... so we're probably stuck with needing to join to a query.
Comment #16
larowlan12: comment-statistics-service.12.patch queued for re-testing.
Comment #18
larowlanreroll
Comment #21
jhodgdonAnother note: The comment ranking stuff for Node search is not actually working at the moment in Core. See
#893302: Search ranking based on the factor "number of comments" & "No of Page Views" is broken
That issue is RTBC... I would advise waiting on this patch until that one has gone in, because different code will need to be put into the ranking stuff in this patch.
Comment #22
larowlanThanks, following that one now
Comment #23
larowlan18: comment-statistics-service.17.patch queued for re-testing.
Comment #25
larowlanmeh
Comment #26
dawehner+1 for not adding into again into the comment manager.
Soome kind of documentation would be cool
what about just using else? I would guess that the EntitOwnerInterface guaranties ensures an owner.
I guess they are stdClass es?
Comment #27
larowlanStill returns NULL for some implementations (entity_test), which {comment_statistics} schema doesn't allow. The fail above shows this (thats why my comment was 'meh' - HEAD does the same as this).
Fixed docs issues
Thanks for the review
Comment #28
jhodgdonA few docs things to fix, mostly on the new Interface:
a)
In contrast to #26 item 4, if these really are stdClass objects, the right thing is @return object[].
https://drupal.org/node/1354#types
b)
All functions should start with a 3rd-person verb like "Reads" not "Read". Several are not.
c)
Description should end in . and also "id" should be "ID" (id == ego, superego, etc.; ID == identifier).
d) typo:
and -> an
e) And on the Controller:
Is it an array or an interface or an array of interfaces? Type and docs do not agree.
f) Total nitpick on the Controller:
Probably only want one blank line here? This is between createInstance() and buildQuery().
Comment #29
larowlanFixes #27
We should write PHPCS sniffs for some of those items, as none were highlighted by my IDE, attention to detail++
Comment #30
dawehnerThe feedback from jhodgon got adressed.
Andypost questioned whether services should depend on the current user. I would argue at the moment that it is not a problem if they are, as even if it will be changed, we can change it.
Comment #31
jhodgdonIn comment #21 I asked if this issue could wait until #893302: Search ranking based on the factor "number of comments" & "No of Page Views" is broken is taken care of... The code you've put into the statistics stuff is not actually working code. Could we postpone this or is it urgent?
That other issue had been at RTBC for ages until webchick put it back to "needs review" yesterday, and these two issues clash... I just don't really want to get the current non-working code put into a completely different spot in Core when there's another issue that is trying to make sure the code actually works (with tests) out there.
Comment #32
jhodgdonI did not intentionally delete those files. See
#2191619: New on-page comment form is deleting all hidden files :(
Terrible bug!!!!!!
Comment #33
larowlanHappy to wait
Comment #34
jhodgdon#893302: Search ranking based on the factor "number of comments" & "No of Page Views" is broken got committed.
However, I found a PostgreSQL bug in the statistics.module code that is very similar to the comment.module code, so I'm addressing both on #2195907: Search ranking for number of views fails in PostgreSQL, which has a working patch (I hope), which again touches the comment_ranking() and comment_cron() code that this patch is using too.
Comment #35
jhodgdonAnd by the way, since this issue is closer to being done, I won't ask again for this one to be postponed, I guess.
Comment #36
jhodgdon29: comment-stats.28.patch queued for re-testing.
Comment #38
larowlanre-roll after #2028025: Expand CommentInterface to provide methods
Comment #40
larowlanComment #41
benjy commentedComment overflows the 80 char limit.
Is this the wrong way around?
Comment #42
jhodgdonJust a note to reviewers/committers: this will conflict with #2195907: Search ranking for number of views fails in PostgreSQL, which has updated code that will need to get into the hook_cron and hook_ranking pieces of this patch (or the new methods they call) so that it will consistently work with PostgreSQL.
Setting this to Needs Work on the basis of #41.
Also, just a thought that the code in the hook_cron() would be easier to understand if it explicitly passed in 'node' as the entity type when calling the getMaximumCount() method. Without that, it is not obvious until you go to the interface/class docs (which might not be easy to find and/or even know what class it is if you are in comment.module) that it's getting the max count for nodes by default. Putting that in there would help self-document the code. Talking about here:
making that last line say getMaximumCount('node'). Also just to point out that the line being removed did not specify an entity type, so technically this is a change in behavior; however, it's the right change in behavior for this purpose, since it's being used by the NodeSearch plugin for ranking search results on nodes.
Comment #43
larowlanFixed 41.1
Re 41.2, we don't store the commenter's name if they're logged in, we have that in {users}.name - this is to store anonymous users's name, as entered on the comment form.
Comment #44
larowlaninterdiff
Comment #45
benjy commentedSince we're leaning towards been explicit I don't see why we should even have the default on the interface?
public function getMaximumCount($entity_type = 'node');Could we just remove it?
Comment #46
larowlanfixes 45
Comment #47
benjy commentedLooks good to me.
Comment #48
andypostAwesome! RTBC +1
This could be useful to find the most commented entity type ;)
Comment #49
jhodgdonUmmmm... What is this:
It seems like this is inconsistently used in the code. For instance, I only see it being called once, and if we are not maintaining comment entity statistics, then the comment ranking won't work, right? And wouldn't it be configuration rather than state anyway? Very confusing. Maybe out of scope for this patch, but ... it seems like if you're going to have this as a service then the service should be configured to be on/off consistently?
Comment #50
larowlanIts for upgrade paths only, in fact migrate now relies on it for its stubbing.
Comment #51
jhodgdonRE #50: a comment to that effect might be useful. :)
Comment #52
andypostRE#50 - I think better to file follow-up to make this configurable. Suppose better to have ability to turn of statistics on per entity basis
Probably #148849: Refactor {comment_entity_statistics} into performant Field the nice candidate and next step
Comment #53
andypostMaybe we should add here the check for entity type (fieldable) as #2195915-7: Cannot save text filter config using PostgreSQL if Comment is enabled [blocks installation!]
Comment #54
alexpottcomment-statistics-service.46.patch no longer applies.
Comment #55
benjy commentedStraight reroll
Comment #56
jhodgdonCan we add a code comment as suggested in #49-51?
Comment #57
yesct commentedSo, you want the comment here?
should similar comment go here? Or is the comment already explaining the same?
Comment #58
andypostdiscussed with @fago in IRC: the patch makes conversion but we still affected by the entity cache because there's no ability to use multiple loading of this kind of data for calculated fields.
Comment #59
jhodgdonRE #57, yes. In comment #49, I noticed this line of code and had no idea what it meant. larowland explained it in comment #50, and it seemed to me that a comment in the code explaining it might be sensible, since it wasn't obvious what it was about. And yes, in both places I think.
Regarding that second spot, this seems to contradict the answer I got in #50. Let's figure out what it's actually for and document it please?
Comment #60
larowlanThere is already this comment in both places:
Do we really need anything more than that? This already exists in HEAD.
Re-roll.
This now blocks #2205215: {comment} and {comment_entity_statistics} only support integer entity ids (which is critical because it fixes some SQL issues now that entity-ids can be strings) which also provides the scope to make this a UI setting per field.
Can we leave the comment as is and make it configurable per-field over there?
Comment #61
andypostback to rtbc
Comment #62
jhodgdonRE #60, OK.
Comment #63
jhodgdonWe had a PostgreSQL issue in the comment rankings for search and its patch was just committed:
#2195907: Search ranking for number of views fails in PostgreSQL
(I made note previously on both issues that they would conflict)...
So
a) This patch probably needs a reroll.
b) This patch needs the new code for the ranking stuff currently in the newly-updated comment_ranking() put into
the new class's getRankingInfo() method.
Comment #64
larowlanSome of the ranking changes match #2205215: {comment} and {comment_entity_statistics} only support integer entity ids changes - nice!
Re-roll
Comment #65
jhodgdonThanks for the quick reroll! The search ranking stuff looks correct to me. Back to RTBC. I'm assuming that was all you changed in this reroll (aside from any other context stuff that needed rerolling).
Comment #66
alexpottcomment-statistics-service.64.patch no longer applies.
Comment #67
larowlanreroll, it was just comments, coding standards changes
Comment #68
sutharsan commentedComment #69
alexpottcomment-statistics-service.67.patch no longer applies.
Comment #70
andypostre-roll, collision in use clause
Comment #72
andypostRe-roll after #2195915: Cannot save text filter config using PostgreSQL if Comment is enabled [blocks installation!]
Comment #74
larowlan72: comment-statistics-service.72.patch queued for re-testing.
Comment #75
andypostTest failure is random, seems #2216909: Random test failure in ConfigTranslationUiTest does not fix it
Comment #77
andypostFor toolbar #2216701: Random test failure in ToolbarAdminMenuTest
Comment #78
yesct commented72: comment-statistics-service.72.patch queued for re-testing.
Comment #79
andypostBoth random failures was fixed
Comment #80
catchCommitted/pushed to 8.x, thanks!
Comment #83
roderikReopening issue, because the error I found is purely related to this one, and because I'd like to ask you something.
The read() method does not say what the interface documentation says it does. It does not return an array but a Database\Statement (iterable) object. Fix attached. Also attached for clarity / how I caught this: a patch that should be part of #2068331: Convert comment SQL queries to the Entity Query API but isn't yet, because its last changed line generates a "Fatal error: Cannot use object of type Drupal\Core\Database\Statement as array"
So, question. Does this fact mean there should be a (unit?) test for this?
(Or instead, is there already (going to be) some magical thing that tests whether all output types of all classes match the documentation?)
Comment #84
jhodgdonPlease do not reopen fixed issues. Instead, open a new issue, and mark it as "related" to this issue. Then come back to this issue and add a comment about your new issue.
Comment #85
roderikOK, will do in future. #2259209: Fix CommentStatistics::read()
Comment #86
roderikFYI: followup that cleans up some existing queries/code to use the CommentStatistics service: for review at #2280861: CommentStatistics service followup