Giter VIP home page Giter VIP logo

distraught's People

Contributors

dependabot[bot] avatar esvinson avatar jwdotjs avatar mattlorey avatar maxkorp avatar soxbox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

distraught's Issues

Rollbar Error Grouping

Workerserver errors are getting grouped today. Try exploding the queue_name on periods and use _.startCase to prevent the grouping of all similarly named queues

Implement count_estimate

In a GQL query a developer can request a collection's records and count:

screen shot 2016-12-23 at 12 57 29 pm

But some PG collections get so large that running a count query is inefficient and it might be beneficial to use the count_estimate query explained here.

We should add a new option to all collections to request the countEstimate.

screen shot 2016-12-23 at 12 59 19 pm

Merge Requirements

  • Add a note in the readme that to use this option, the users will need the count_estimate() function to be created on the Postgres server the GraphQL is interfacing with
  • Update builder.js to allow countEstimate as a field
  • Update adapter/knex.js such that if countEstimate is a field that was requested, it will call the count_estimate function with the records query as the only parameter passed to it (as a single string)

Example:

select count_estimate('select * from users')

Camelcase Enhancements

  • Check if the input passed to camelCase is an array, if so map over the array and camelcase each object.
  • Remove from gql.helpers namespace
  • Apply to snakeCase as well

Very Simple Caching System

We need to create a Cache class that ties into Redis.

  • In the constructor, link this.redis to a singleton instance of Redis using the environment variable for REDIS_URL. If there is none, fail silently.

  • If there is no REDIS_URL in the environment variables throw a TError saying the class cannot method get until a REDIS_URL is added. Create a get function that takes one parameter: key (string). Pull from redis cache with that key, if it fails return null. It should return the value if setting the cache was successful.

  • If there is no REDIS_URL in the environment variables throw a TError saying the class cannot method set until a REDIS_URL is added. Create a set function that takes three parameters: key (string), value (any), ttl (number until expiration, check if Redis uses seconds or ms and document that in the function notes). Set a default TTL of 5 minutes if none is set.

  • If value is a Fn, execute the Fn.

  • If the result of Fn is a promise, await the result.

  • If the promise is rejected, throw new TError(Unable to set cache for key ${key}, promise rejected, {promiseErr});

  • Create a Fn called getOrSet that takes the same params, as set Fn, but will try a get internally before calling the function to execute fetching the data. Returns promise of a value.

Export from distraught, a singleton instance of the cache Class.

Users can then following get/set pattern:


import {cache} from 'distraught'

async fetchReport() {
    let report = cache.get('report');

    if (! report) {
         report = cache.set('report', await ReportModel.fetch());
         //  or specify a TTL with: report = cache.set('report', await ReportModel.fetch(), 3000);
    }

    return report;
}

or users can utilize the getOrSet fn:

import {cache} from 'distraught';

fetchReport() {
    return cache.getOrSet('report', ReportModel.fetch, 3000); // returns promise
}

Update twilio sendtext

{
  "error": {
    "message": "RestClient has been removed from this version of the library. Please refer to https://www.twilio.com/docs/libraries/node for more information.",
  }
}

Rerunning init to add a connection re-adds existing connections.

Example:

const D = require("distraught");
D.init({
  db: {
    connection1: { connection: process.env.DB_URL },
  },
});

D.init({
  db: {
    connection2: { connection: process.env.DB_URL },
  },
});
// we would get a message about "DB connection connection1 already added"

When we're looping through the each calls in the init section of the code we should make sure the key doesn't exist before we call the respecting addDatabase/addHeretic/addCache calls.

GQL queries - Cache Key, Cache TTL (blocked by #27)

  • Add ability to cache results of GQL queries if user specifies cacheKey and cacheTTL on their pgObject

On a pgObject, if the user specifies a cacheKey, the queries will try and check for matches against Redis, before querying PG.

Note: The cacheKey should be letters/numbers (no symbols or spaces), this is actually a prefix to the actual key that is used.

  1. If cacheKey exists on the PG object, check that REDIS_URL is in the environment vars. If not, throw a TError saying cacheKey cannot be used without a valid REDIS_URL
  2. Check that the cacheKey is letters/numbers only, otherwise throw a TError about invalid cacheKey
  3. If there is no cacheTTL, default to 5 minutes
  4. Take all user-specified filters and hash them. Then use the get method from the cache singleton instance (#27) to try and return results from cache.
  5. If there is no resultset, execute the GQL query, then use the set method from the cache singleton instance to set the cache using the cacheKey-${filterHash} as the full key, the resultset as the value, and the TTL as either the cacheTTL specified on the pgObject or the default of 5 minutes

No session option

Need an option in the httpServer to not require sessions.
If something is just and API that uses JWT for auth it shouldn't need a SESSION_SECRET defined.

Upgrade GraphQL to v0.8.*

GraphQL v0.8.* supports NullValue which currently gets stripped from payloads.

This is probably a breaking change for the existing applications

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.