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