Skip to content
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

Olympia: Support for forum thread labels/tags #2422

Closed
Lezek123 opened this issue May 21, 2021 · 1 comment
Closed

Olympia: Support for forum thread labels/tags #2422

Lezek123 opened this issue May 21, 2021 · 1 comment
Assignees

Comments

@Lezek123
Copy link
Contributor

Lezek123 commented May 21, 2021

List of changes needed for Olympia in order to support forum thread tags functionality:

Runtime

  • create_thread extrinsic - change title argument name to metadata, as it will become the encoded thread metadata which includes both thread title and tags
  • edit_thread_title extrinsic and ThreadTitleUpdated event - change names to edit_thread_metadata and ThreadMetadataUpdated, as this extrinsic will be used to update both forum title and tags.

Protobuf messages

We need a new protobuf message to represent the thread metadata:

message ForumThreadMetadata {
  optional string title = 1;
  repeated string tags = 2;
}

It will be used both when creating a new thread and updating a thread, as described in the Query node mappings section below.

Query node input schema

We need a new entity like ForumThreadTag, with many-to-many relationship to ForumThread, ie.:

type ForumThreadTag @entity {
  "Tag name"
  name: String! @unique

  "Threads that use this tag"
  threads: [ForumThread!] @derivedFrom(field: "tags")

  "Number of threads that use this tag"
  threadsCount: Int!
}

type ForumThread @entity {
  "Runtime thread id"
  id: ID!

  "Related thread tags"
  tags: [ForumThreadTag!]

  # ...
}

Notice that currently we need a separate threadsCount field in ForumThreadTag, because aggregate queries are not yet supported (Joystream/hydra#195)

Query node mappings

After deserializing the tags from ForumThreadMetadata, the query node will:

  • slice the array so that only the max. allowed number of tags per thread remains (ie. 4)
  • iterate over remaining tags and insert a new ForumThreadTag into the database for each tag that doesn't yet have a matching entry in the database (we could additionaly normalize all tags with, for example, toLowerCase() and trim(), in order to avoid duplications).

When handling ThreadMetadataUpdated event:

  • no value for tags would mean we leave current thread tags unaffected
  • any value (including empty array) means we override all existing tags relationships with the new ones (we don't support atomically adding / removing just a single tag)
  • we must update threadCount accordingly in all unset / set tags.

Pioneer v2

The input schema menioned above should be enough to support all the queries required by Pioneer, for example:

query forumThreadTags(orderBy: name_DESC, limit: 50) {
  name
  threadsCount
} 

Listing tags alphabetically

query forumThreadTags(orderBy: threadsCount_DESC, limit: 10) {
  name
  threadsCount
} 

Listing 10 most popular tags

query forumThreadTags(where:{ name_startsWith: "Pr" ) {
  name
} 

Listing all existing tags starting with characters entered by the user

Related tags

In order to find tags that are related to a tag, Pioneer can execute a query like:

query forumThreads(where: { tags_some: { name_eq: "SomeTag" } }) {
  tags {
    name
  }
}

Then count how many times each unique tag appears in the result. The tags that appear most often are most related to the tag that's beeing searched for (SomeTag in this example), meaning, they most often appear together with SomeTag.

@iorveth
Copy link
Contributor

iorveth commented Dec 27, 2021

is closed by #2537 & #2547

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants