mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
server-ts: Port share/shaca/shaca_loader
This commit is contained in:
parent
b3c2602620
commit
7c76d28f75
@ -4,7 +4,7 @@ const safeCompare = require('safe-compare');
|
|||||||
const ejs = require("ejs");
|
const ejs = require("ejs");
|
||||||
|
|
||||||
const shaca = require('./shaca/shaca');
|
const shaca = require('./shaca/shaca');
|
||||||
const shacaLoader = require('./shaca/shaca_loader.js');
|
const shacaLoader = require('./shaca/shaca_loader');
|
||||||
const shareRoot = require('./share_root');
|
const shareRoot = require('./share_root');
|
||||||
const contentRenderer = require('./content_renderer.js');
|
const contentRenderer = require('./content_renderer.js');
|
||||||
const assetPath = require('../services/asset_path');
|
const assetPath = require('../services/asset_path');
|
||||||
|
4
src/share/shaca/entities/rows.ts
Normal file
4
src/share/shaca/entities/rows.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
type SNoteRow = [ string, string, string, string, string, string, boolean ];
|
||||||
|
type SBranchRow = [ string, string, string, string, string, boolean ];
|
||||||
|
type SAttributeRow = [ string, string, string, string, string, boolean, number ];
|
||||||
|
type SAttachmentRow = [ string, string, string, string, string, string, string ];
|
@ -6,8 +6,6 @@ import AbstractShacaEntity = require('./abstract_shaca_entity');
|
|||||||
import SNote = require('./snote');
|
import SNote = require('./snote');
|
||||||
import { Blob } from '../../../services/blob-interface';
|
import { Blob } from '../../../services/blob-interface';
|
||||||
|
|
||||||
type AttachmentRow = [ string, string, string, string, string, string, string ];
|
|
||||||
|
|
||||||
class SAttachment extends AbstractShacaEntity {
|
class SAttachment extends AbstractShacaEntity {
|
||||||
private attachmentId: string;
|
private attachmentId: string;
|
||||||
private ownerId: string;
|
private ownerId: string;
|
||||||
@ -18,7 +16,7 @@ class SAttachment extends AbstractShacaEntity {
|
|||||||
/** used for caching of images */
|
/** used for caching of images */
|
||||||
private utcDateModified: string;
|
private utcDateModified: string;
|
||||||
|
|
||||||
constructor([attachmentId, ownerId, role, mime, title, blobId, utcDateModified]: AttachmentRow) {
|
constructor([attachmentId, ownerId, role, mime, title, blobId, utcDateModified]: SAttachmentRow) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.attachmentId = attachmentId;
|
this.attachmentId = attachmentId;
|
||||||
|
@ -4,8 +4,6 @@ import SNote = require("./snote");
|
|||||||
|
|
||||||
const AbstractShacaEntity = require('./abstract_shaca_entity');
|
const AbstractShacaEntity = require('./abstract_shaca_entity');
|
||||||
|
|
||||||
type AttributeRow = [ string, string, string, string, string, boolean, number ];
|
|
||||||
|
|
||||||
class SAttribute extends AbstractShacaEntity {
|
class SAttribute extends AbstractShacaEntity {
|
||||||
|
|
||||||
attributeId: string;
|
attributeId: string;
|
||||||
@ -16,7 +14,7 @@ class SAttribute extends AbstractShacaEntity {
|
|||||||
value: string;
|
value: string;
|
||||||
isInheritable: boolean;
|
isInheritable: boolean;
|
||||||
|
|
||||||
constructor([attributeId, noteId, type, name, value, isInheritable, position]: AttributeRow) {
|
constructor([attributeId, noteId, type, name, value, isInheritable, position]: SAttributeRow) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.attributeId = attributeId;
|
this.attributeId = attributeId;
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
import AbstractShacaEntity = require('./abstract_shaca_entity');
|
import AbstractShacaEntity = require('./abstract_shaca_entity');
|
||||||
import SNote = require('./snote');
|
import SNote = require('./snote');
|
||||||
|
|
||||||
type BranchRow = [ string, string, string, string, string, boolean ];
|
|
||||||
|
|
||||||
class SBranch extends AbstractShacaEntity {
|
class SBranch extends AbstractShacaEntity {
|
||||||
|
|
||||||
private branchId: string;
|
private branchId: string;
|
||||||
@ -14,7 +12,7 @@ class SBranch extends AbstractShacaEntity {
|
|||||||
private isExpanded: boolean;
|
private isExpanded: boolean;
|
||||||
isHidden: boolean;
|
isHidden: boolean;
|
||||||
|
|
||||||
constructor([branchId, noteId, parentNoteId, prefix, isExpanded]: BranchRow) {
|
constructor([branchId, noteId, parentNoteId, prefix, isExpanded]: SBranchRow) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.branchId = branchId;
|
this.branchId = branchId;
|
||||||
|
@ -15,8 +15,6 @@ const CREDENTIALS = 'shareCredentials';
|
|||||||
|
|
||||||
const isCredentials = (attr: SAttribute) => attr.type === 'label' && attr.name === CREDENTIALS;
|
const isCredentials = (attr: SAttribute) => attr.type === 'label' && attr.name === CREDENTIALS;
|
||||||
|
|
||||||
type NoteRow = [ string, string, string, string, string, string, boolean ];
|
|
||||||
|
|
||||||
class SNote extends AbstractShacaEntity {
|
class SNote extends AbstractShacaEntity {
|
||||||
noteId: string;
|
noteId: string;
|
||||||
private title: string;
|
private title: string;
|
||||||
@ -34,7 +32,7 @@ class SNote extends AbstractShacaEntity {
|
|||||||
targetRelations: SAttribute[];
|
targetRelations: SAttribute[];
|
||||||
attachments: SAttachment[];
|
attachments: SAttachment[];
|
||||||
|
|
||||||
constructor([noteId, title, type, mime, blobId, utcDateModified, isProtected]: NoteRow) {
|
constructor([noteId, title, type, mime, blobId, utcDateModified, isProtected]: SNoteRow) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.noteId = noteId;
|
this.noteId = noteId;
|
||||||
|
@ -14,7 +14,7 @@ export default class Shaca {
|
|||||||
private shareRootNote!: SNote | null;
|
private shareRootNote!: SNote | null;
|
||||||
/** true if the index of all shared subtrees is enabled */
|
/** true if the index of all shared subtrees is enabled */
|
||||||
private shareIndexEnabled!: boolean;
|
private shareIndexEnabled!: boolean;
|
||||||
private loaded!: boolean;
|
loaded!: boolean;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.reset();
|
this.reset();
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const sql = require('../sql');
|
import sql = require('../sql');
|
||||||
const shaca = require('./shaca');
|
import shaca = require('./shaca');
|
||||||
const log = require('../../services/log');
|
import log = require('../../services/log');
|
||||||
const SNote = require('./entities/snote');
|
import SNote = require('./entities/snote');
|
||||||
const SBranch = require('./entities/sbranch');
|
import SBranch = require('./entities/sbranch');
|
||||||
const SAttribute = require('./entities/sattribute');
|
import SAttribute = require('./entities/sattribute');
|
||||||
const SAttachment = require('./entities/sattachment');
|
import SAttachment = require('./entities/sattachment');
|
||||||
const shareRoot = require('../share_root');
|
import shareRoot = require('../share_root');
|
||||||
const eventService = require('../../services/events');
|
import eventService = require('../../services/events');
|
||||||
|
|
||||||
function load() {
|
function load() {
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
@ -35,7 +35,7 @@ function load() {
|
|||||||
|
|
||||||
const noteIdStr = noteIds.map(noteId => `'${noteId}'`).join(",");
|
const noteIdStr = noteIds.map(noteId => `'${noteId}'`).join(",");
|
||||||
|
|
||||||
const rawNoteRows = sql.getRawRows(`
|
const rawNoteRows = sql.getRawRows<SNoteRow>(`
|
||||||
SELECT noteId, title, type, mime, blobId, utcDateModified, isProtected
|
SELECT noteId, title, type, mime, blobId, utcDateModified, isProtected
|
||||||
FROM notes
|
FROM notes
|
||||||
WHERE isDeleted = 0
|
WHERE isDeleted = 0
|
||||||
@ -45,7 +45,7 @@ function load() {
|
|||||||
new SNote(row);
|
new SNote(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
const rawBranchRows = sql.getRawRows(`
|
const rawBranchRows = sql.getRawRows<SBranchRow>(`
|
||||||
SELECT branchId, noteId, parentNoteId, prefix, isExpanded, utcDateModified
|
SELECT branchId, noteId, parentNoteId, prefix, isExpanded, utcDateModified
|
||||||
FROM branches
|
FROM branches
|
||||||
WHERE isDeleted = 0
|
WHERE isDeleted = 0
|
||||||
@ -56,7 +56,7 @@ function load() {
|
|||||||
new SBranch(row);
|
new SBranch(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
const rawAttributeRows = sql.getRawRows(`
|
const rawAttributeRows = sql.getRawRows<SAttributeRow>(`
|
||||||
SELECT attributeId, noteId, type, name, value, isInheritable, position, utcDateModified
|
SELECT attributeId, noteId, type, name, value, isInheritable, position, utcDateModified
|
||||||
FROM attributes
|
FROM attributes
|
||||||
WHERE isDeleted = 0
|
WHERE isDeleted = 0
|
||||||
@ -66,14 +66,12 @@ function load() {
|
|||||||
new SAttribute(row);
|
new SAttribute(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
const rawAttachmentRows = sql.getRawRows(`
|
const rawAttachmentRows = sql.getRawRows<SAttachmentRow>(`
|
||||||
SELECT attachmentId, ownerId, role, mime, title, blobId, utcDateModified
|
SELECT attachmentId, ownerId, role, mime, title, blobId, utcDateModified
|
||||||
FROM attachments
|
FROM attachments
|
||||||
WHERE isDeleted = 0
|
WHERE isDeleted = 0
|
||||||
AND ownerId IN (${noteIdStr})`);
|
AND ownerId IN (${noteIdStr})`);
|
||||||
|
|
||||||
rawAttachmentRows.sort((a, b) => a.position < b.position ? -1 : 1);
|
|
||||||
|
|
||||||
for (const row of rawAttachmentRows) {
|
for (const row of rawAttachmentRows) {
|
||||||
new SAttachment(row);
|
new SAttachment(row);
|
||||||
}
|
}
|
||||||
@ -93,7 +91,7 @@ eventService.subscribe([eventService.ENTITY_CREATED, eventService.ENTITY_CHANGED
|
|||||||
shaca.reset();
|
shaca.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
export = {
|
||||||
load,
|
load,
|
||||||
ensureLoad
|
ensureLoad
|
||||||
};
|
};
|
@ -23,7 +23,7 @@ function getRow<T>(query: string, params: string[] = []): T {
|
|||||||
return dbConnection.prepare(query).get(params) as T;
|
return dbConnection.prepare(query).get(params) as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getColumn<T>(query: string, params = []): T[] {
|
function getColumn<T>(query: string, params: string[] = []): T[] {
|
||||||
return dbConnection.prepare(query).pluck().all(params) as T[];
|
return dbConnection.prepare(query).pluck().all(params) as T[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user