db put should take parent's shared by default.

This commit is contained in:
Eric van der Vlist 2023-02-13 10:56:48 +01:00
parent 9ea29b368f
commit e445a7e1af
4 changed files with 22 additions and 14 deletions

View File

@ -214,7 +214,7 @@ export const watchDbLegacy = async () => {
// // store, // // store,
// // allDocs, // // allDocs,
// docs, // docs,
// state: state(), // state: state(),gi
// }); // });
return docs; return docs;
}; };
@ -223,7 +223,7 @@ export const watchDbLegacy = async () => {
await until( await until(
() => () =>
state()?.sync?.paused && state()?.sync?.paused &&
state()?.sync?.lastSeq >= state()?.localUpdateSeq, state()?.sync?.lastSeq >= state()?.localUpdateSeq - 1, // I wonder why this can happen !
1000 1000
); );

View File

@ -1,5 +1,6 @@
import { debounce, slice } from 'lodash'; import { debounce, slice } from 'lodash';
import { getWpt } from '../db/wpt'; import { getWpt } from '../db/wpt';
import { getParentId } from '../lib/docuri';
import { returnAgain } from '../workers/dispatcher-worker'; import { returnAgain } from '../workers/dispatcher-worker';
import { getAllGpxes, getGpx } from './gpx'; import { getAllGpxes, getGpx } from './gpx';
import { put } from './lib'; import { put } from './lib';
@ -50,17 +51,7 @@ const changeHandler = async (change: any) => {
} }
sendUpdate(globalThis.watches.get(id)); sendUpdate(globalThis.watches.get(id));
const tokens = id.split('/').slice(0, -1); const parentId = getParentId(id);
if (['1wpt', '2rte', '3trk'].includes(tokens.at(-1))) {
tokens.splice(-1);
}
const parentId = tokens.join('/');
// console.log({
// caller: 'ChangeHandler',
// change,
// watches: globalThis.watches,
// parentId,
// });
if (parentId === 'gpx') { if (parentId === 'gpx') {
const gpxes = await getAllGpxes(); const gpxes = await getAllGpxes();

View File

@ -1,5 +1,6 @@
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import { state } from '../db-admin/health-legacy'; import { state } from '../db-admin/health-legacy';
import { getParentId } from '../lib/docuri';
declare global { declare global {
var localDb: any; var localDb: any;
@ -19,7 +20,14 @@ export const put = async (
try { try {
current = await targetDb.get(_id); current = await targetDb.get(_id);
} catch { } catch {
current = { _rev: undefined, doc: cloneDeep(defaultDoc) }; const parentId = getParentId(_id);
let shared;
try {
const parent = await db.get(parentId);
// console.log({ caller: 'put', parent });
shared = parent.shared;
} catch {}
current = { _rev: undefined, shared, doc: cloneDeep(defaultDoc) };
} }
try { try {
putDoc = { putDoc = {

View File

@ -130,4 +130,13 @@ export const route = (route, coding = {}) => {
}; };
}; };
export const getParentId = (id) => {
const tokens = id.split('/').slice(0, -1);
if (['1wpt', '2rte', '3trk'].includes(tokens.at(-1))) {
tokens.splice(-1);
}
const parentId = tokens.join('/');
return parentId;
};
export default route; export default route;