MCPcopy Create free account
hub / github.com/totaljs/framework / findRelationDocument

Function findRelationDocument

graphdb.js:804–838  ·  view source on GitHub ↗
(self, relid, callback)

Source from the content-addressed store, hash-verified

802
803// Finds a free space for new relation in "pushRelationDocument"
804function findRelationDocument(self, relid, callback) {
805
806 if (!relid) {
807 callback(null, 0);
808 return;
809 }
810
811 var offset = offsetDocument(self, relid);
812 var buf = U.createBufferSize(self.header.documentsize);
813
814 Fs.read(self.fd, buf, 0, buf.length, offset, function(err, size) {
815
816 if (err || !size) {
817 callback(err, 0);
818 return;
819 }
820
821 var count = buf.readUInt16LE(15);
822 if (count + 1 > self.header.relationlimit) {
823 // Checks if the relation index has next relation
824
825 if (relid === buf.readUInt32LE(7))
826 return;
827
828 relid = buf.readUInt32LE(7);
829 if (relid)
830 setImmediate(findRelationDocument, self, relid, callback);
831 else
832 callback(null, 0);
833 } else {
834 // Free space for this relation
835 callback(null, relid);
836 }
837 });
838}
839
840// Pushs "documentindex" to "index" document (document with all relations)
841function pushRelationDocument(self, index, relation, documentindex, initializator, callback, between, recovered) {

Callers 1

pushRelationDocumentFunction · 0.85

Calls 2

callbackFunction · 0.85
offsetDocumentFunction · 0.85

Tested by

no test coverage detected