MCPcopy Index your code
hub / github.com/totaljs/framework / remDocumentAll

Function remDocumentAll

graphdb.js:980–1041  ·  view source on GitHub ↗
(self, index, callback, count)

Source from the content-addressed store, hash-verified

978}
979
980function remDocumentAll(self, index, callback, count) {
981
982 var offset = offsetDocument(self, index);
983 var buf = U.createBufferSize(17);
984
985 // type (1b) = from: 0
986 // index (1b) = from: 1
987 // state (1b) = from: 2
988 // pageindex (4b) = from: 3
989 // relationindex (4b) = from: 7 (it's for relations between two documents in TYPE_RELATION page)
990 // parentindex (4b) = from: 11
991 // size/count (2b) = from: 15
992 // data = from: 17
993
994 if (!count)
995 count = 0;
996
997 Fs.read(self.fd, buf, 0, buf.length, offset, function() {
998
999 var relid = buf.readUInt32LE(7);
1000
1001 if (buf[2] === STATE_REMOVED) {
1002 if (relid)
1003 remDocumentAll(self, relid, callback, count);
1004 else
1005 callback(null, count);
1006 return;
1007 }
1008
1009 buf.writeUInt8(STATE_REMOVED, 2);
1010 buf.writeUInt16LE(0, 15);
1011
1012 if (buf[0] === TYPE_CLASS)
1013 self.$classes[buf[1]].findfreeslots = true;
1014
1015 var pageindex = buf.readUInt32LE(3);
1016
1017 Fs.write(self.fd, buf, 0, buf.length, offset, function() {
1018
1019 // Updates "documents" in the current page
1020 updPageMeta(self, pageindex, function(err, buf) {
1021
1022 // type (1b) = from: 0
1023 // index (1b) = from: 1
1024 // documents (2b) = from: 2
1025 // freeslots (1b) = from: 4
1026 // parentindex (4b) = from: 5
1027
1028 var documents = buf.readUInt16LE(2);
1029 buf.writeUInt16LE(documents > 0 ? documents - 1 : documents, 2);
1030 count++;
1031
1032 setImmediate(function() {
1033 if (relid)
1034 remDocumentAll(self, relid, callback, count);
1035 else
1036 callback(null, count);
1037 });

Callers 1

remDocumentFunction · 0.85

Calls 3

offsetDocumentFunction · 0.85
callbackFunction · 0.85
updPageMetaFunction · 0.85

Tested by

no test coverage detected