backup
This commit is contained in:
parent
af63473f8a
commit
679adb60bd
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -9,10 +9,20 @@ import {
|
||||||
getCollectionNodeByKeyOrNodeKey, getNodeForCollectionPath,
|
getCollectionNodeByKeyOrNodeKey, getNodeForCollectionPath,
|
||||||
isCollectionRecord, isAncestor,
|
isCollectionRecord, isAncestor,
|
||||||
} from '../templateApi/hierarchy';
|
} from '../templateApi/hierarchy';
|
||||||
import { joinKey, safeKey, $ } from '../common';
|
import { joinKey, safeKey, $, getFileFromKey } from '../common';
|
||||||
|
|
||||||
|
const RECORDS_PER_FOLDER = 1000;
|
||||||
|
|
||||||
const allIdChars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-';
|
const allIdChars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-';
|
||||||
|
|
||||||
|
const _new_getShardPath = (recordNode, key) => {
|
||||||
|
const id = getFileFromKey(key);
|
||||||
|
|
||||||
|
const determineShardFactors = (currentRecordCount, factors=[]) => {
|
||||||
|
const thisFactor = currentRecordCount / 1000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const allIdsStringsForFactor = (collectionNode) => {
|
const allIdsStringsForFactor = (collectionNode) => {
|
||||||
const factor = collectionNode.allidsShardFactor;
|
const factor = collectionNode.allidsShardFactor;
|
||||||
const charRangePerShard = 64 / factor;
|
const charRangePerShard = 64 / factor;
|
||||||
|
@ -65,48 +75,9 @@ export const getAllIdsShardKey = (appHierarchy, collectionKey, recordId) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getOrCreateShardFile = async (datastore, allIdsKey) => {
|
|
||||||
try {
|
|
||||||
return await datastore.loadFile(allIdsKey);
|
|
||||||
} catch (eLoad) {
|
|
||||||
try {
|
|
||||||
await datastore.createFile(allIdsKey, '');
|
|
||||||
return '';
|
|
||||||
} catch (eCreate) {
|
|
||||||
throw new Error(
|
|
||||||
`Error loading, then creating allIds ${allIdsKey
|
|
||||||
} : LOAD : ${eLoad.message
|
|
||||||
} : CREATE : ${eCreate}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getShardFile = async (datastore, allIdsKey) => {
|
|
||||||
try {
|
|
||||||
return await datastore.loadFile(allIdsKey);
|
|
||||||
} catch (eLoad) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const addToAllIds = (appHierarchy, datastore) => async (record) => {
|
|
||||||
const allIdsKey = getAllIdsShardKey(
|
|
||||||
appHierarchy,
|
|
||||||
getParentKey(record.key),
|
|
||||||
record.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
let allIds = await getOrCreateShardFile(datastore, allIdsKey);
|
|
||||||
|
|
||||||
allIds += `${allIds.length > 0 ? ',' : ''}${record.id}`;
|
|
||||||
|
|
||||||
await datastore.updateFile(allIdsKey, allIds);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getAllIdsIterator = app => async (collection_Key_or_NodeKey) => {
|
export const getAllIdsIterator = app => async (collection_Key_or_NodeKey) => {
|
||||||
collection_Key_or_NodeKey = safeKey(collection_Key_or_NodeKey);
|
collection_Key_or_NodeKey = safeKey(collection_Key_or_NodeKey);
|
||||||
const targetNode = getCollectionNodeByKeyOrNodeKey(
|
const recordNode = getCollectionNodeByKeyOrNodeKey(
|
||||||
app.hierarchy,
|
app.hierarchy,
|
||||||
collection_Key_or_NodeKey,
|
collection_Key_or_NodeKey,
|
||||||
);
|
);
|
||||||
|
@ -138,8 +109,8 @@ export const getAllIdsIterator = app => async (collection_Key_or_NodeKey) => {
|
||||||
|
|
||||||
const ancestors = $(getFlattenedHierarchy(app.hierarchy), [
|
const ancestors = $(getFlattenedHierarchy(app.hierarchy), [
|
||||||
filter(isCollectionRecord),
|
filter(isCollectionRecord),
|
||||||
filter(n => isAncestor(targetNode)(n)
|
filter(n => isAncestor(recordNode)(n)
|
||||||
|| n.nodeKey() === targetNode.nodeKey()),
|
|| n.nodeKey() === recordNode.nodeKey()),
|
||||||
orderBy([n => n.nodeKey().length], ['asc']),
|
orderBy([n => n.nodeKey().length], ['asc']),
|
||||||
]); // parents first
|
]); // parents first
|
||||||
|
|
||||||
|
@ -149,7 +120,7 @@ export const getAllIdsIterator = app => async (collection_Key_or_NodeKey) => {
|
||||||
parentRecordKey,
|
parentRecordKey,
|
||||||
currentNode.collectionName,
|
currentNode.collectionName,
|
||||||
);
|
);
|
||||||
if (currentNode.nodeKey() === targetNode.nodeKey()) {
|
if (currentNode.nodeKey() === recordNode.nodeKey()) {
|
||||||
return [
|
return [
|
||||||
await getAllIdsIteratorForCollectionKey(
|
await getAllIdsIteratorForCollectionKey(
|
||||||
currentCollectionKey,
|
currentCollectionKey,
|
||||||
|
@ -191,39 +162,5 @@ export const getAllIdsIterator = app => async (collection_Key_or_NodeKey) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAllIdsFromShard = async (datastore, shardKey) => {
|
|
||||||
const allIdsStr = await getShardFile(datastore, shardKey);
|
|
||||||
|
|
||||||
const allIds = [];
|
|
||||||
let currentId = '';
|
|
||||||
for (let i = 0; i < allIdsStr.length; i++) {
|
|
||||||
const currentChar = allIdsStr.charAt(i);
|
|
||||||
const isLast = (i === allIdsStr.length - 1);
|
|
||||||
if (currentChar === ',' || isLast) {
|
|
||||||
if (isLast) currentId += currentChar;
|
|
||||||
allIds.push(currentId);
|
|
||||||
currentId = '';
|
|
||||||
} else {
|
|
||||||
currentId += currentChar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return allIds;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const removeFromAllIds = (appHierarchy, datastore) => async (record) => {
|
|
||||||
const shardKey = getAllIdsShardKey(
|
|
||||||
appHierarchy,
|
|
||||||
getParentKey(record.key),
|
|
||||||
record.id,
|
|
||||||
);
|
|
||||||
const allIds = await getAllIdsFromShard(datastore, shardKey);
|
|
||||||
|
|
||||||
const newIds = $(allIds, [
|
|
||||||
pull(record.id),
|
|
||||||
join(','),
|
|
||||||
]);
|
|
||||||
|
|
||||||
await datastore.updateFile(shardKey, newIds);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default getAllIdsIterator;
|
export default getAllIdsIterator;
|
||||||
|
|
|
@ -9,7 +9,6 @@ import {
|
||||||
} from '../templateApi/hierarchy';
|
} from '../templateApi/hierarchy';
|
||||||
import { _deleteIndex } from '../indexApi/delete';
|
import { _deleteIndex } from '../indexApi/delete';
|
||||||
import { transactionForDeleteRecord } from '../transactions/create';
|
import { transactionForDeleteRecord } from '../transactions/create';
|
||||||
import { removeFromAllIds } from '../indexing/allIds';
|
|
||||||
import { permission } from '../authApi/permissions';
|
import { permission } from '../authApi/permissions';
|
||||||
|
|
||||||
export const deleteRecord = (app, disableCleanup = false) => async key => {
|
export const deleteRecord = (app, disableCleanup = false) => async key => {
|
||||||
|
@ -44,8 +43,6 @@ export const _deleteRecord = async (app, key, disableCleanup) => {
|
||||||
|
|
||||||
await deleteFiles(app, key);
|
await deleteFiles(app, key);
|
||||||
|
|
||||||
await removeFromAllIds(app.hierarchy, app.datastore)(record);
|
|
||||||
|
|
||||||
if (!disableCleanup) { await app.cleanupTransactions(); }
|
if (!disableCleanup) { await app.cleanupTransactions(); }
|
||||||
|
|
||||||
await app.datastore.deleteFolder(key);
|
await app.datastore.deleteFolder(key);
|
||||||
|
|
|
@ -2,9 +2,7 @@ import {
|
||||||
cloneDeep,
|
cloneDeep,
|
||||||
flatten,
|
flatten,
|
||||||
map,
|
map,
|
||||||
filter,
|
filter} from 'lodash/fp';
|
||||||
isEqual
|
|
||||||
} from 'lodash/fp';
|
|
||||||
import { initialiseChildCollections } from '../collectionApi/initialise';
|
import { initialiseChildCollections } from '../collectionApi/initialise';
|
||||||
import { validate } from './validate';
|
import { validate } from './validate';
|
||||||
import { _load, getRecordFileName } from './load';
|
import { _load, getRecordFileName } from './load';
|
||||||
|
@ -13,10 +11,8 @@ import {
|
||||||
} from '../common';
|
} from '../common';
|
||||||
import {
|
import {
|
||||||
getFlattenedHierarchy, getExactNodeForPath,
|
getFlattenedHierarchy, getExactNodeForPath,
|
||||||
isRecord, getNode, isSingleRecord,
|
isRecord, getNode, fieldReversesReferenceToNode,
|
||||||
fieldReversesReferenceToNode,
|
|
||||||
} from '../templateApi/hierarchy';
|
} from '../templateApi/hierarchy';
|
||||||
import { addToAllIds } from '../indexing/allIds';
|
|
||||||
import {
|
import {
|
||||||
transactionForCreateRecord,
|
transactionForCreateRecord,
|
||||||
transactionForUpdateRecord,
|
transactionForUpdateRecord,
|
||||||
|
@ -51,9 +47,6 @@ export const _save = async (app, record, context, skipValidation = false) => {
|
||||||
if(!recordNode)
|
if(!recordNode)
|
||||||
throw new Error("Cannot find node for " + record.key);
|
throw new Error("Cannot find node for " + record.key);
|
||||||
|
|
||||||
if(!isSingleRecord(recordNode))
|
|
||||||
await addToAllIds(app.hierarchy, app.datastore)(recordClone);
|
|
||||||
|
|
||||||
const transaction = await transactionForCreateRecord(
|
const transaction = await transactionForCreateRecord(
|
||||||
app, recordClone,
|
app, recordClone,
|
||||||
);
|
);
|
||||||
|
@ -131,3 +124,7 @@ const fieldsThatReferenceThisRecord = (app, recordNode) => $(app.hierarchy, [
|
||||||
flatten,
|
flatten,
|
||||||
filter(fieldReversesReferenceToNode(recordNode)),
|
filter(fieldReversesReferenceToNode(recordNode)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const recordFolderPath = (recordNode, key) => {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue