Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Data Structures

Michael Edlinger edited this page Jun 5, 2014 · 8 revisions

Data Structures

Out of date. We're moving fast

How our app handles data and what structures it uses.

Chats stored on RethinkDb

{
  users: [], // list of user UUIDs
  name: '', // name of the chat
  id: '', // UUID of the chat
  timestamp: r.now() // RethinkDbs date datatype
}

Simple enough.

Messages sent through Redis

{
  id: '', // UUID of the message
  message: '', // the contents of the message
  chatId: '', // UUID of the chat it is part of
  user: '', // UUID of the user who sent the message
  timestamp: '' // string with the time the message was created
}

This entire object is then made a string via JSON.stringify and sent over Redis' pubsub system. Most of this is simple except for the timestamp. The timestamp is created at the time nodejs created the message, and is created by taking a new Date() and making it a string (date.toString()). When the message is received by other node servers, they should be made into objects again with JSON.parse() and the timestamp should then be converted back to an object with message.timestamp = Date(message.timestamp)

Messages stored in RethinkDb

{
  id: '', // UUID of the message
  message: '', // the contents of the message
  chatId: '', // UUID of the chat it is part of
  user: '', // UUID of the user who sent the message
  username: '', // username of the user who sent the message
  timestamp: r.now() // Rethinkdb's way of storing dates
}

This is very similar to the way messages are sent through Redis, but it has some key differences. It is stored as a json document (so it never has to be converted to a string), and the timestamp is a special datatype in Rethinkdb (millisecond precision).

Users stored in RethinkDb

Not finished

{
  googId: '', // the users Google given ID
  googName: '', // the users name as stored in Google
  googImgUrl: '', // the URL of the users profile pic stored in Google
  googProfUrl: '', // URL of the users Google profile
  username: '', the users JetStream username
  firstName: '', the users first name
  lastName: '', the users last name
  password: '', the users hashed password
  salt: '', // the salt for the password hash
  chatList: [], // a list of all the chat IDs that a user is a part of
  id: '' // JetStream given UUID
}

Users have a bulk of the data about them.