Updated: Comment #N

Problem/Motivation

ForumManager is doing too much, much like #2188287: Split CommentManager in two
We still have SQL queries in forum.module that need to be behind a swappable service.

Proposed resolution

Create ForumRepository for SQL stuff in forum.module
Move relevant bits of ForumManager into ForumRepository.

Remaining tasks

Review

User interface changes

None

API changes

New ForumRepositoryInterface
ForumManagerInterface::updateIndex() removed.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

larowlan’s picture

Assigned: Unassigned » larowlan

tackling this week

chx’s picture

ForumRepository? Why not the forum storage controller??

larowlan’s picture

Yeah can be ForumStorageController but its not a storage controller in the EntityStorageController sense of the word.
So perhaps ForumStorage makes more sense?
Naming things is hard :)

tstoeckler’s picture

Well, we're renaming FooStorageController to FooStorage, so that would be the same conflict :-/

tstoeckler’s picture

larowlan’s picture

ForumRepository it is then ;)

chx’s picture

Sure.

larowlan’s picture

Status: Active » Needs review
FileSize
20.1 KB

First attempt

method names follow the CRUD acronym, duplicated for the index

With this patch, there is no SQL in forum.module

larowlan’s picture

green :)

andypost’s picture

  1. +++ b/core/modules/forum/lib/Drupal/forum/ForumRepository.php
    @@ -0,0 +1,170 @@
    +  public function updateIndex(NodeInterface $node) {
    ...
    +    $count = $this->database->query("SELECT COUNT(cid) FROM {comment} c INNER JOIN {forum_index} i ON c.entity_id = i.nid WHERE c.entity_id = :nid AND c.field_id = 'node__comment_forum' AND c.entity_type = 'node' AND c.status = :status", array(
    ...
    +    if ($count > 0) {
    +      // Comments exist.
    +      $last_reply = $this->database->queryRange("SELECT cid, name, created, uid FROM {comment} WHERE entity_id = :nid AND field_id = 'node__comment_forum' AND entity_type = 'node' AND status = :status ORDER BY cid DESC", 0, 1, array(
    ...
    +      $this->database->update('forum_index')
    ...
    +          'comment_count' => $count,
    +          'last_comment_timestamp' => $last_reply->created,
    

    The comment exists, because count>0.
    So second query needs to fetch "created" only

  2. +++ b/core/modules/forum/lib/Drupal/forum/ForumRepository.php
    @@ -0,0 +1,170 @@
    +      // Comments do not exist.
    +      // @todo This should be actually filtering on the desired node language
    +      //   and just fall back to the default language.
    +      $node = $this->database->query('SELECT uid, created FROM {node_field_data} WHERE nid = :nid AND default_langcode = 1', array(':nid' => $nid))->fetchObject();
    +      $this->database->update('forum_index')
    ...
    +          'comment_count' => 0,
    +          'last_comment_timestamp' => $node->created,
    

    The $node is already passed as argument, suppose query could be skipped

jibran’s picture

Status: Needs review » Needs work

NW as per #10.

larowlan’s picture

Issue tags: +Needs reroll

adding reroll tag

hairqles’s picture

Status: Needs work » Needs review
FileSize
49.63 KB

The patch has been rerolled.

Status: Needs review » Needs work

The last submitted patch, 13: forum-storage-2205185.13.patch, failed testing.

hairqles’s picture

continue the work on the reroll

hairqles’s picture

Status: Needs work » Needs review
FileSize
163.45 KB

Attached the updated patch.

hairqles’s picture

FileSize
168.76 KB

Updated the patch according to comment #10

hairqles’s picture

Removed deprecated comment.

The last submitted patch, 17: forum-storage-2205185.17.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 18: forum-storage-2205185.18.patch, failed testing.

hairqles’s picture

hairqles’s picture

Status: Needs work » Needs review
hairqles’s picture

Issue tags: -Needs reroll
andypost’s picture

Status: Needs review » Reviewed & tested by the community

This issue is a part of #2068325: [META] Convert entity SQL queries to the Entity Query API
Suppose that's should be enough because all queries here are encapsulated in single service and the most of them used to change data.
Queries that fetches data are highly optimized and does not need any alter for translation

andypost’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

The issue summary says that ForumManagerInterface is removed - does not appear to be.

I guess the plan wrt to change notices is to expand https://drupal.org/node/2079767?

+++ b/core/modules/forum/lib/Drupal/forum/ForumManager.php
@@ -513,44 +513,6 @@ public function unreadTopics($term, $uid) {
-      ':status' => CommentInterface::PUBLISHED,

Can remove the use ... CommentInterface from the manager.

larowlan’s picture

Title: Split ForumManager into ForumViewBuilder and ForumRepository » Split up ForumManager to create ForumRepository
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update
FileSize
536 bytes
20.19 KB

@hairqles, next time could you please post an interdiff? thanks.
Re-roll and removes the surplus use statement.

larowlan’s picture

Issue summary: View changes

Updated issue summary to reflect patch (which is still green).

andypost’s picture

Status: Needs review » Reviewed & tested by the community

rtbc again

xjm’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/forum/lib/Drupal/forum/ForumManagerInterface.php
@@ -96,12 +96,4 @@ public function checkNodeType(NodeInterface $node);
   public function unreadTopics($term, $uid);

+++ b/core/modules/forum/lib/Drupal/forum/ForumRepositoryInterface.php
@@ -0,0 +1,94 @@
+ * Handles CRUD operations to {forum_index} table.
...
+interface ForumRepositoryInterface {

Naming things is hard, indeed. :) I have no idea what a forum repository is. If it's not ForumStorage because it's not an entity storage handler... can we give it a longer and more descriptive name? ForumIndexSomething would be better since that makes it clear it manages the {forum_index} table.

larowlan’s picture

FileSize
5.73 KB
20 KB

grep -ilr ForumRepository core | while read r; do gsed -i 's/ForumRepository/ForumIndexStorage/g;s/forum_repository/forum_index_storage/g' $r;done

larowlan’s picture

Title: Split up ForumManager to create ForumRepository » Split up ForumManager to create ForumIndexStorage

Status: Needs review » Needs work

The last submitted patch, 31: forum-storage-2205185-2.28.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
FileSize
610 bytes
20.28 KB

doh, needed

gfind core -name ForumRepository*  | while read r; do mv $r ${r/ForumRepository/ForumIndexStorage};done

too

andypost’s picture

Status: Needs review » Reviewed & tested by the community

so "naming" resolved

roderik’s picture

FWIW and referring to #2/#3:
I am going to assume that the suffix 'Storage' is not off limits for anyone creating their non-entity storage.

Which I agree with - and which is a larger thing than just this issue. I mean why would entities monopolize the term 'Storage'? Are we going to forbid e.g. metatag.module to call a class MetatagStorage?

(...so this class could have been named ForumStorage too :p but I don't mind one way or the other.)

Just noting this, as the guy who is probably going to take a stab at creating TrackerStorage...

xjm’s picture

Re: #36: Well the thing is that it's not the actual forum storage... it's a lookup table. :) So ForumIndexStorage is indeed a clear/correct name.

xjm’s picture

The change record https://drupal.org/node/2079767 does not have a reference to this issue yet; should it? Will it need an update?

larowlan’s picture

I'll update the change record once in

xjm’s picture

Thanks @larowlan. I've edited https://drupal.org/node/2079767 to add a reference to this issue.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 34: forum-storage-2205185-2.29.patch, failed testing.

andypost’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
20.28 KB

re-roll

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 42: forum-storage-2205185-2.29.42.patch, failed testing.

andypost’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
20.26 KB

proper merge

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 44: forum-storage-2205185-2.29.44.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Fail was in HEAD

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/forum/forum.services.yml
@@ -12,3 +12,6 @@ services:
+  forum.repository:
+    class: Drupal\forum\ForumIndexStorage
+    arguments: ['@database', '@forum_manager']

But we're still calling the service forum.repository? In my mind this should forum.index_storage

marcingy’s picture

Assigned: larowlan » marcingy
slashrsm’s picture

Assigned: marcingy » Unassigned
Status: Needs work » Needs review
FileSize
20.11 KB
4.84 KB

Reroll to PSR-4 and fixed service name.

marcingy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good if green.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 1b34836 and pushed to 8.x. Thanks!

  • Commit 1b34836 on 8.x by alexpott:
    Issue #2205185 by larowlan, hairqles, andypost, slashrsm: Split up...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.