typedb / typedb-studio

TypeDB Studio (IDE)
https://typedb.com
Mozilla Public License 2.0
191 stars 43 forks source link

Move the post-query processing jobs to a dedicated module #186

Closed sorsaffari closed 2 years ago

sorsaffari commented 5 years ago

Currently, the pot-processing that takes place after running queries, is done outside the scope of the CanvasDataBuider. Because of this, the node objects produced by CanvasDataBuider must include properties of the original Graql Concepts.

Ideally, node objects should only contain properties expected by Visjs and therefore the post-processing job should be moved to the CanvasDataBuider

marco-scoppetta commented 5 years ago

As for our discussion, an update on this:

computeAttributes() (or another name) should stay as a separate method, but it should accept Answers or Concepts as parameters, so that building canvas nodes and calling methods on Concepts remain 2 different things working on 2 different type of objects.

Pseudo code for computeAttributesOnInstances(answers):

/**
* Given an array of answers return an array of Objects { id, attributes}
* Used to asynchronously fetch all the attributes attached to a set of concepts
*/

function computeAttributesOnInstances(answers){
  const concepts = extractConceptsFromAnserws(answers); // it can use concepts directly as a parameter, this is just an hypothesis
  const instances = concepts.filter(c => c.isThing());
  return Promise.all(instances.map(loadAttributes(instance)));
}

"private" async function loadAttributes(instance){
   const attributes = await (await instance.attributes()).collect();
   const attributesWithValues = await attributesWithValues(attributes);
   return Object.assign({id: instance.id , attributes: attributesWithValues });
}

// This function can be rewritten in a more elegant fashion, but which will be less performant, 
// up to us to decide whether prioritise elegance or performance
"private" function attributesWithValues(attributes){
   return Promise.all(attributes.map(async (concept) => {
      const attribute = {};
        await Promise.all([
          concept.type().then(type => type.label()).then((label) => { attribute.type = label; }),
          concept.value().then((value) => { attribute.value = value; }),
        ]);
      return attribute;
    }))
}

We can then have another method computeAttributesOnTypes() or they can stay together with another internal if, again this is just a draft

marco-scoppetta commented 5 years ago

Once this is done let's remember to remove txService from the nodes when we build them!

alexjpwalker commented 2 years ago

This issue is no longer relevant as Studio uses new architecture.