-
Notifications
You must be signed in to change notification settings - Fork 40
feat(comment-replies): add single threading on comments #520
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
base: master
Are you sure you want to change the base?
Conversation
416f07a to
8db5551
Compare
| indexer_queue_name = "events" | ||
|
|
||
| # ResultItem configurations | ||
| links_item = { |
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.
Would it make sense to add replies to the links? This would make the code on the frontend more consistent
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.
Added
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.
Thanks for adding these. Sorry to ask about this again, would it be possible to avoid showing the replies and reply links when the RequestEvent in question is a reply? Maybe using the when argument
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.
The link works also for children as it is always point to the parent document. I did that so you dont have to check conditionally for the links. But I am happy to discuss why do you think it is better to remove it.
1771f8f to
8d82923
Compare
c8b7f5c to
3e745ac
Compare
palkerecsenyi
left a comment
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.
Looks good and it makes sense! It's definitely a lot simpler and cleaner
| "parent_child": { | ||
| "type": "join", | ||
| "relations": { | ||
| "parent": "child" |
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 could also consider using less abstract names as in the OpenSearch example, maybe {"comment": "reply"}. Just to make it a bit more readable. But I think {"parent": "child"} is pretty good too so it's up to you!
| if event.parent_id is not None: | ||
| # Check if event type supports children | ||
| if hasattr(event, "type") and event.type: | ||
| if not getattr(event.type, "allow_children", False): |
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 could refactor this to use guard clauses instead for slightly better readability, just to avoid nesting the if statements. But this is also not too big of an issue
| request_type = current_request_type_registry.lookup(vars["request_type"]) | ||
| vars.update({"id": obj.id, "request_id": obj.request_id}) | ||
| parent_id = obj.parent_id if obj.parent_id else obj.id | ||
| vars.update({"parent_id": parent_id}) | ||
| vars.update(request_type._update_link_config(**vars)) |
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.
| request_type = current_request_type_registry.lookup(vars["request_type"]) | |
| vars.update({"id": obj.id, "request_id": obj.request_id}) | |
| parent_id = obj.parent_id if obj.parent_id else obj.id | |
| vars.update({"parent_id": parent_id}) | |
| vars.update(request_type._update_link_config(**vars)) | |
| request_type = current_request_type_registry.lookup(vars["request_type"]) | |
| parent_id = obj.parent_id if obj.parent_id else obj.id | |
| vars.update( | |
| {"id": obj.id, "request_id": obj.request_id, "parent_id": parent_id} | |
| ) | |
| vars.update(request_type._update_link_config(**vars)) |
| links_tpl=LinksTemplate( | ||
| self.config.links_replies, | ||
| context={ | ||
| "parent_id": parent_id, | ||
| "request_id": str(request.id), | ||
| "args": params, | ||
| }, | ||
| ), |
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 could also be expressed as a call to self.links_tpl_factory
| """Log event type.""" | ||
|
|
||
| type_id = "L" | ||
| """Allow log events to preserve parent-child structure (e.g., deleted comments).""" |
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.
nit: this comment doesn't match the variable 🙈
| # Query structure: | ||
| # - must: filter to this request | ||
| # - must_not: exclude children (events with parent_id) | ||
| # - should: optionally add children preview via has_child + inner_hits | ||
| search = search.query( | ||
| "bool", | ||
| must=[ | ||
| dsl.Q("term", request_id=str(request.id)), | ||
| ], | ||
| must_not=[ | ||
| dsl.Q("exists", field="parent_id"), # Exclude replies | ||
| ], | ||
| should=[ | ||
| dsl.Q( | ||
| "has_child", | ||
| type="child", | ||
| query=dsl.Q("match_all"), | ||
| score_mode="none", | ||
| inner_hits={ | ||
| "name": "replies_preview", | ||
| "size": preview_size, | ||
| "sort": [{"created": "desc"}], | ||
| }, | ||
| ), | ||
| ], | ||
| minimum_should_match=0, # Make should clause optional | ||
| ) |
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 I get what you meant by this being less code, even though we're using a relatively "complex" feature like join types.
My only concern is actually performance, i.e. is the overhead of two queries (one for fetching the first 10 parents + one agg query to fetch the last 5 comments for each parent), that much bigger? Insert/update performance is ok to be worse IMHO, since the UI anyways can handle this in an optimistic way.
I read the tests in the CodiMD, but wasn't convinced of a clear answer, so maybe that's the only thing to discuss IRL.
3e745ac to
05d8491
Compare
| if hasattr(self._record, 'parent_id') and self._record.parent_id: | ||
| arguments['routing'] = str(self._record.parent_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.
Nice handling of this here, I thought it would have caused more problems in general.
One more consideration is to take into account bulk-indexing, which would now need to add the routing=<parent_id> param for all child comments/replies...
Would it make sense to bake this whole logic instead into the indexer? I think we have some functions there for pre/post-processing indexing args.
ac48770 to
5c57b81
Compare
5c57b81 to
88c4bb6
Compare
bf10998 to
67e8bbd
Compare
closes #490
addresses inveniosoftware/rfcs#107