Fix racing condition

This commit is contained in:
rijkvanzanten
2020-09-11 16:59:29 -04:00
parent 5b99264cf1
commit 7dc858aee2
3 changed files with 23 additions and 12 deletions

View File

@@ -204,7 +204,8 @@ export default defineComponent({
isEmpty(state.relations[0].one_field) ||
isEmpty(state.relations[1].many_collection) ||
isEmpty(state.relations[1].many_field) ||
isEmpty(state.relations[1].one_collection)
isEmpty(state.relations[1].one_collection) ||
isEmpty(state.relations[1].one_primary)
);
}
@@ -229,13 +230,15 @@ export default defineComponent({
}
await Promise.all(
state.newCollections.map((newCollection: Partial<Collection>) => {
state.newCollections.map((newCollection: Partial<Collection> & { $type: string }) => {
delete newCollection.$type;
return api.post(`/collections`, newCollection);
})
);
await Promise.all(
state.newFields.map((newField: Partial<Field>) => {
state.newFields.map((newField: Partial<Field> & { $type: string }) => {
delete newField.$type;
return api.post(`/fields/${newField.collection}`, newField);
})
);

View File

@@ -316,16 +316,13 @@ function initLocalStore(
delete state.fieldData.schema;
delete state.fieldData.type;
const syncNewCollectionsM2M = throttle((
[junctionCollection, manyCurrent, manyRelated, relatedCollection],
[oldJunctionCollection, oldManyCurrent, oldManyRelated, oldRelatedCollection]
) => {
state.newCollections = state.newCollections.filter((col: any) => [junctionCollection, relatedCollection, oldJunctionCollection, oldRelatedCollection].includes(col.collection) === false);
state.newFields = state.newFields
.filter((field: Partial<Field>) => [manyCurrent, manyRelated, relatedCollection, oldManyCurrent, oldManyRelated, oldRelatedCollection].includes(field.field) === false);
const syncNewCollectionsM2M = throttle(([junctionCollection, manyCurrent, manyRelated, relatedCollection]) => {
state.newCollections = state.newCollections.filter((col: any) => ['junction', 'related'].includes(col.$type) === false);
state.newFields = state.newFields.filter((field: Partial<Field> & { $type: string }) => ['manyCurrent', 'manyRelated'].includes(field.$type) === false);
if (collectionExists(junctionCollection) === false) {
state.newCollections.push({
$type: 'junction',
collection: junctionCollection,
fields: [
{
@@ -344,24 +341,33 @@ function initLocalStore(
if (fieldExists(junctionCollection, manyCurrent) === false) {
state.newFields.push({
$type: 'manyCurrent',
collection: junctionCollection,
field: manyCurrent,
type: fieldsStore.getPrimaryKeyFieldForCollection(junctionCollection)?.type,
type: collectionExists(junctionCollection) ? fieldsStore.getPrimaryKeyFieldForCollection(junctionCollection)?.type : 'integer',
schema: {},
meta: {
hidden: true,
}
});
}
if (fieldExists(junctionCollection, manyRelated) === false) {
state.newFields.push({
$type: 'manyRelated',
collection: junctionCollection,
field: manyRelated,
type: collectionExists(relatedCollection) ? fieldsStore.getPrimaryKeyFieldForCollection(relatedCollection)?.type : 'integer',
schema: {},
meta: {
hidden: true,
}
});
}
if (collectionExists(relatedCollection) === false) {
state.newCollections.push({
$type: 'related',
collection: relatedCollection,
fields: [
{
@@ -377,6 +383,8 @@ function initLocalStore(
]
})
}
console.log(state.newCollections, state.newFields);
}, 50);
if (!isExisting) {

View File

@@ -1,5 +1,5 @@
<template>
<private-view :title="collectionInfo.name">
<private-view :title="collectionInfo && collectionInfo.name">
<template #headline>{{ $t('settings_data_model') }}</template>
<template #title-outer:prepend>
<v-button class="header-icon" rounded icon exact to="/settings/data-model">