mirror of
https://github.com/frappe/books.git
synced 2024-11-09 23:30:56 +00:00
fix: uninserted doc cache router break
- explicit drop from cache on delete if notinserted
This commit is contained in:
parent
d9415233f5
commit
5a3b87333e
@ -74,7 +74,7 @@ export class DocHandler {
|
||||
|
||||
doc = this.getNewDoc(schemaName, { name }, false);
|
||||
await doc.load();
|
||||
this.#addToCache(doc, false);
|
||||
this.#addToCache(doc);
|
||||
|
||||
return doc;
|
||||
}
|
||||
@ -101,7 +101,7 @@ export class DocHandler {
|
||||
const doc = new Model!(schema, data, this.fyo, isRawValueMap);
|
||||
doc.name ??= this.getTemporaryName(schema);
|
||||
if (cacheDoc) {
|
||||
this.#addToCache(doc, true);
|
||||
this.#addToCache(doc);
|
||||
}
|
||||
|
||||
return doc;
|
||||
@ -131,7 +131,7 @@ export class DocHandler {
|
||||
* Cache operations
|
||||
*/
|
||||
|
||||
#addToCache(doc: Doc, isNew: boolean) {
|
||||
#addToCache(doc: Doc) {
|
||||
if (!doc.name) {
|
||||
return;
|
||||
}
|
||||
@ -144,9 +144,7 @@ export class DocHandler {
|
||||
this.#setCacheUpdationListeners(schemaName);
|
||||
}
|
||||
|
||||
if (!isNew) {
|
||||
this.docs.get(schemaName)![name] = doc;
|
||||
}
|
||||
this.docs.get(schemaName)![name] = doc;
|
||||
|
||||
// singles available as first level objects too
|
||||
if (schemaName === doc.name) {
|
||||
@ -163,14 +161,14 @@ export class DocHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
this.#removeFromCache(doc.schemaName, name);
|
||||
this.#addToCache(doc, false);
|
||||
this.removeFromCache(doc.schemaName, name);
|
||||
this.#addToCache(doc);
|
||||
});
|
||||
}
|
||||
|
||||
#setCacheUpdationListeners(schemaName: string) {
|
||||
this.fyo.db.observer.on(`delete:${schemaName}`, (name: string) => {
|
||||
this.#removeFromCache(schemaName, name);
|
||||
this.removeFromCache(schemaName, name);
|
||||
});
|
||||
|
||||
this.fyo.db.observer.on(
|
||||
@ -181,13 +179,13 @@ export class DocHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
this.#removeFromCache(schemaName, names.oldName);
|
||||
this.#addToCache(doc, false);
|
||||
this.removeFromCache(schemaName, names.oldName);
|
||||
this.#addToCache(doc);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#removeFromCache(schemaName: string, name: string) {
|
||||
removeFromCache(schemaName: string, name: string) {
|
||||
const docMap = this.docs.get(schemaName);
|
||||
delete docMap?.[name];
|
||||
}
|
||||
|
@ -915,6 +915,10 @@ export class Doc extends Observable<DocValue | Doc[]> {
|
||||
}
|
||||
|
||||
async delete() {
|
||||
if (this.notInserted && this.name) {
|
||||
this.fyo.doc.removeFromCache(this.schemaName, this.name);
|
||||
}
|
||||
|
||||
if (!this.canDelete) {
|
||||
return;
|
||||
}
|
||||
|
@ -6,15 +6,15 @@
|
||||
<AutoComplete
|
||||
v-if="templateList.length"
|
||||
:df="{
|
||||
fieldtype: 'AutoComplete',
|
||||
fieldname: 'templateName',
|
||||
label: t`Template Name`,
|
||||
target: 'PrintTemplate',
|
||||
options: templateList,
|
||||
options: templateList.map((n) => ({ label: n, value: n })),
|
||||
}"
|
||||
input-class="text-base py-0 h-8"
|
||||
class="w-56"
|
||||
:border="true"
|
||||
:value="templateName"
|
||||
:value="templateName ?? ''"
|
||||
@change="onTemplateNameChange"
|
||||
/>
|
||||
</template>
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import ChartOfAccounts from 'src/pages/ChartOfAccounts.vue';
|
||||
import CommonForm from 'src/pages/CommonForm/CommonForm.vue';
|
||||
import Dashboard from 'src/pages/Dashboard/Dashboard.vue';
|
||||
@ -29,12 +28,10 @@ const routes: RouteRecordRaw[] = [
|
||||
edit: QuickEditForm,
|
||||
},
|
||||
props: {
|
||||
default: (route) => {
|
||||
return {
|
||||
schemaName: route.params.schemaName,
|
||||
name: route.params.name,
|
||||
};
|
||||
},
|
||||
default: (route) => ({
|
||||
schemaName: route.params.schemaName,
|
||||
name: route.params.name,
|
||||
}),
|
||||
edit: (route) => route.query,
|
||||
},
|
||||
},
|
||||
@ -62,9 +59,7 @@ const routes: RouteRecordRaw[] = [
|
||||
pageTitle,
|
||||
};
|
||||
},
|
||||
edit: (route) => {
|
||||
return route.query;
|
||||
},
|
||||
edit: (route) => route.query,
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -117,5 +112,4 @@ const routes: RouteRecordRaw[] = [
|
||||
];
|
||||
|
||||
const router = createRouter({ routes, history: createWebHistory() });
|
||||
|
||||
export default router;
|
||||
|
Loading…
Reference in New Issue
Block a user