Skip to content

aerugo/discourse-graphryder

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Graphryder plugin for Discourse

This is a plugin designed to install and use RedisGraph with a Discourse instance.

It uses the existing redis installation baked into Discourse into order to construct a graph of relationships between nodes.

Currently, a built binary of the RedisGraph module (version 2.0.11-rc1) is included with this plugin, and installed on Discourse startup, which allows storing nodes and edges within Redis.

Installation

Instructions for installing Discourse plugins can be found here.

Take note that the first time this plugin is installed, it will install the RedisGraph module onto Discourse's Redis instance. Subsequent deploys will not perform this step.

Once the plugin is running, it will begin auto-syncing updates which occur.

Starting the instance with the GRAPHRYDER_IMPORT ENV variable set will cause a full import of the existing database from Postgres into RedisGraph.

GRAPHRYDER_IMPORT bundle exec rails s

API

This plugin exposes a single endpoint,

/graphryder/query

which accepts a RedisGraph query, and responds with

It will return a hash with keys, one for each RETURN value in the query. For instance, the following query:

{
  "query": "MATCH (post:post) RETURN post, count(*) as count"
}

would return JSON as follows:

{
  "post": [{...}, {...}, {...}, {...}, {...}], // json representations of post data stored in RedisGraph
  "count": 5 // Number of records returned
}

In order to use this endpoint, a user must either be authenticated as an admin (using a generated Admin API key), or a member of a group named annotators

At the time of this writing, the intended consumer of this API is the Existing graphryder API

Importing from ActiveRecord

In order to import the RedisGraph graph from ActiveRecord, run the given importer command:

Graphryder::Importer.initialize!

This will append all nodes in ActiveRecord onto the existing graph (it should not create any duplicates if they exist in RedisGraph already).

In order to delete the graph and re-import from scratch, pass the force option:

Graphryder::Importer.initialize!(force: true)

Data model

As of this writing, the fields synced to RedisGraph are as follows:

User:
  fields:
    label (username)
    avatar (avatar_template)
    timestamp (updated_at)
    url (https://<instance>.com/users/<username>)

Topic:
  fields:
    label (id)
    title (title)
    timestamp (updated_at)
    url (url)

  relationships:
    AUTHORSHIP (user)

Post:
  fields:
    label (id)
    topic_id (topic_id)
    number (post_number)
    content (cooked)
    timestamp (updated_at)
    url (url)

  relationships:
    AUTHORSHIP (user)
    COMMENTS (topic)
    COMMENTS (reply_to_post)

AnnotatorStore::Tag
  fields:
    label (id)
    name (name)
    description (description)
    timestamp (updated_at)

  relationships:
    AUTHORSHIP (creator)

AnnotatorStore::TagName
  fields:
    label (name)
    timestamp (updated_at)

  relationships:
    NAMED (tag)

AnnotatorStore::Annotation
  fields:
    label (id)
    quote (quote)
    timestamp (updated_at)

  relationships:
    AUTHORSHIP (user)
    REFERS_TO (tag)

The code which does this can be viewed in the Updater class (the code written there should be considered the source of truth)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%