Skip to content

Commit

Permalink
change the way frontend detects content change which works even if no…
Browse files Browse the repository at this point in the history
… new blob is created, fixes #4434
  • Loading branch information
zadam committed Nov 13, 2023
1 parent 69ed364 commit cf06821
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 89 deletions.
116 changes: 58 additions & 58 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@excalidraw/excalidraw": "0.16.1",
"archiver": "6.0.1",
"async-mutex": "0.4.0",
"axios": "1.6.0",
"axios": "1.6.1",
"better-sqlite3": "8.4.0",
"chokidar": "3.5.3",
"cls-hooked": "4.2.2",
Expand All @@ -61,7 +61,7 @@
"express-rate-limit": "7.1.4",
"express-session": "1.17.3",
"fs-extra": "11.1.1",
"helmet": "7.0.0",
"helmet": "7.1.0",
"html": "1.0.0",
"html2plaintext": "2.1.4",
"http-proxy-agent": "7.0.0",
Expand All @@ -73,8 +73,8 @@
"jimp": "0.22.10",
"joplin-turndown-plugin-gfm": "1.0.12",
"jsdom": "22.1.0",
"katex": "^0.16.9",
"marked": "9.1.5",
"katex": "0.16.9",
"marked": "9.1.6",
"mime-types": "2.1.35",
"multer": "1.4.5-lts.1",
"node-abi": "3.51.0",
Expand Down Expand Up @@ -104,7 +104,7 @@
},
"devDependencies": {
"cross-env": "7.0.3",
"electron": "25.9.3",
"electron": "25.9.4",
"electron-builder": "24.6.4",
"electron-packager": "17.1.2",
"electron-rebuild": "3.2.9",
Expand All @@ -119,11 +119,11 @@
"jasmine": "5.1.0",
"jsdoc": "4.0.2",
"jsonc-eslint-parser": "2.4.0",
"lint-staged": "15.0.2",
"lint-staged": "15.1.0",
"lorem-ipsum": "2.0.8",
"nodemon": "3.0.1",
"prettier": "3.0.3",
"rcedit": "4.0.0",
"prettier": "3.1.0",
"rcedit": "4.0.1",
"webpack": "5.89.0",
"webpack-cli": "5.1.4"
},
Expand Down
4 changes: 2 additions & 2 deletions src/becca/entities/abstract_becca_entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class AbstractBeccaEntity {

sql.execute("DELETE FROM blobs WHERE blobId = ?", [oldBlobId]);
// blobs are not marked as erased in entity_changes, they are just purged completely
// this is because technically every keystroke can create a new blob and there would be just too many
// this is because technically every keystroke can create a new blob, and there would be just too many
sql.execute("DELETE FROM entity_changes WHERE entityName = 'blobs' AND entityId = ?", [oldBlobId]);
}

Expand Down Expand Up @@ -230,7 +230,7 @@ class AbstractBeccaEntity {
isErased: false,
utcDateChanged: pojo.utcDateModified,
isSynced: true,
// overriding componentId will cause frontend to think the change is coming from a different component
// overriding componentId will cause the frontend to think the change is coming from a different component
// and thus reload
componentId: opts.forceFrontendReload ? utils.randomString(10) : null
});
Expand Down
3 changes: 3 additions & 0 deletions src/public/app/entities/fnote.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class FNote {
* @type {string}
*/
this.mime = row.mime;

// the main use case to keep this is to detect content change which should trigger refresh
this.blobId = row.blobId;
}

addParent(parentNoteId, branchId, sort = true) {
Expand Down
5 changes: 4 additions & 1 deletion src/public/app/services/froca.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,15 @@ class Froca {

/** @returns {Promise<FBlob>} */
async getBlob(entityType, entityId) {
// I'm not sure why we're not using blobIds directly, it would save us this composite key ...
// perhaps one benefit is that we're always requesting the latest blob, not relying on perhaps faulty/slow
// websocket update?
const key = `${entityType}-${entityId}`;

if (!this.blobPromises[key]) {
this.blobPromises[key] = server.get(`${entityType}/${entityId}/blob`)
.then(row => new FBlob(row))
.catch(e => console.error(`Cannot get blob for ${entityType} '${entityId}'`));
.catch(e => console.error(`Cannot get blob for ${entityType} '${entityId}'`, e));

// we don't want to keep large payloads forever in memory, so we clean that up quite quickly
// this cache is more meant to share the data between different components within one business transaction (e.g. loading of the note into the tab context and all the components)
Expand Down
Loading

0 comments on commit cf06821

Please sign in to comment.