mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 00:36:31 +02:00
feat: update SurfSense plugin to version 0.1.0 with improved description, minimum app version, and license details; enhance queue management with debouncing and refactor status modal for clarity
This commit is contained in:
parent
9fded124fe
commit
b3f0b2e13a
10 changed files with 285 additions and 99 deletions
|
|
@ -2,8 +2,8 @@
|
|||
"id": "surfsense",
|
||||
"name": "SurfSense",
|
||||
"version": "0.1.0",
|
||||
"minAppVersion": "1.4.0",
|
||||
"description": "Sync your Obsidian vault to SurfSense for AI-powered search across all your knowledge sources.",
|
||||
"minAppVersion": "1.5.4",
|
||||
"description": "Turn your vault into a searchable second brain with SurfSense.",
|
||||
"author": "SurfSense",
|
||||
"authorUrl": "https://github.com/MODSetter/SurfSense",
|
||||
"isDesktopOnly": false
|
||||
|
|
|
|||
|
|
@ -1,5 +1,201 @@
|
|||
Copyright (C) 2020-2025 by Dynalist Inc.
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
"id": "surfsense",
|
||||
"name": "SurfSense",
|
||||
"version": "0.1.0",
|
||||
"minAppVersion": "1.4.0",
|
||||
"description": "Sync your Obsidian vault to SurfSense for AI-powered search across all your knowledge sources.",
|
||||
"minAppVersion": "1.5.4",
|
||||
"description": "Turn your vault into a searchable second brain with SurfSense.",
|
||||
"author": "SurfSense",
|
||||
"authorUrl": "https://github.com/MODSetter/SurfSense",
|
||||
"isDesktopOnly": false
|
||||
|
|
|
|||
18
surfsense_obsidian/package-lock.json
generated
18
surfsense_obsidian/package-lock.json
generated
|
|
@ -13,7 +13,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "9.30.1",
|
||||
"@types/node": "^16.11.6",
|
||||
"@types/node": "^20.19.39",
|
||||
"esbuild": "0.25.5",
|
||||
"eslint-plugin-obsidianmd": "0.1.9",
|
||||
"globals": "14.0.0",
|
||||
|
|
@ -839,9 +839,19 @@
|
|||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "16.18.126",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.126.tgz",
|
||||
"integrity": "sha512-OTcgaiwfGFBKacvfwuHzzn1KLxH/er8mluiy8/uM3sGXHaRe73RrSIj01jow9t4kJEW633Ov+cOexXeiApTyAw==",
|
||||
"version": "20.19.39",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.39.tgz",
|
||||
"integrity": "sha512-orrrD74MBUyK8jOAD/r0+lfa1I2MO6I+vAkmAWzMYbCcgrN4lCrmK52gRFQq/JRxfYPfonkr4b0jcY7Olqdqbw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~6.21.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node/node_modules/undici-types": {
|
||||
"version": "6.21.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
|
||||
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"@eslint/js": "9.30.1",
|
||||
"@types/node": "^16.11.6",
|
||||
"@types/node": "^20.19.39",
|
||||
"esbuild": "0.25.5",
|
||||
"eslint-plugin-obsidianmd": "0.1.9",
|
||||
"globals": "14.0.0",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { type Debouncer, debounce } from "obsidian";
|
||||
import type { QueueItem } from "./types";
|
||||
|
||||
/**
|
||||
|
|
@ -64,8 +65,7 @@ export class PersistentQueue {
|
|||
};
|
||||
private draining = false;
|
||||
private stopRequested = false;
|
||||
private flushTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
private onFlush: (() => void) | null = null;
|
||||
private debouncedFlush: Debouncer<[], void> | null = null;
|
||||
|
||||
constructor(initial: QueueItem[], opts: PersistentQueueOptions) {
|
||||
this.items = [...initial];
|
||||
|
|
@ -87,7 +87,8 @@ export class PersistentQueue {
|
|||
}
|
||||
|
||||
setFlushHandler(handler: () => void): void {
|
||||
this.onFlush = handler;
|
||||
// resetTimer: true → each enqueue postpones the flush.
|
||||
this.debouncedFlush = debounce(handler, this.opts.debounceMs, true);
|
||||
}
|
||||
|
||||
enqueueUpsert(path: string): void {
|
||||
|
|
@ -131,8 +132,7 @@ export class PersistentQueue {
|
|||
enqueuedAt: now,
|
||||
attempt: 0,
|
||||
});
|
||||
// Also enqueue an upsert of the new path so its content/metadata
|
||||
// reflects whatever the editor flushed alongside the rename.
|
||||
// Pair with an upsert — content may have changed alongside the rename.
|
||||
this.items.push({ op: "upsert", path: newPath, enqueuedAt: now, attempt: 0 });
|
||||
void this.persist();
|
||||
this.scheduleFlush();
|
||||
|
|
@ -143,19 +143,11 @@ export class PersistentQueue {
|
|||
}
|
||||
|
||||
cancelFlush(): void {
|
||||
if (this.flushTimer !== null) {
|
||||
clearTimeout(this.flushTimer);
|
||||
this.flushTimer = null;
|
||||
}
|
||||
this.debouncedFlush?.cancel();
|
||||
}
|
||||
|
||||
private scheduleFlush(): void {
|
||||
if (!this.onFlush) return;
|
||||
if (this.flushTimer !== null) clearTimeout(this.flushTimer);
|
||||
this.flushTimer = setTimeout(() => {
|
||||
this.flushTimer = null;
|
||||
this.onFlush?.();
|
||||
}, this.opts.debounceMs);
|
||||
this.debouncedFlush?.();
|
||||
}
|
||||
|
||||
async drain(worker: QueueWorker): Promise<DrainSummary> {
|
||||
|
|
@ -181,8 +173,7 @@ export class PersistentQueue {
|
|||
const dropKeys = new Set(result.dropped.map(itemKey));
|
||||
const retryKeys = new Set(result.retry.map(itemKey));
|
||||
|
||||
// Keep any item we didn't explicitly account for in `retry`
|
||||
// so a partial-batch drop never silently loses work.
|
||||
// Items the worker didn't classify get retried — never silently dropped.
|
||||
const unhandled = batch.filter(
|
||||
(b) =>
|
||||
!ackKeys.has(itemKey(b)) &&
|
||||
|
|
|
|||
|
|
@ -1,13 +1,7 @@
|
|||
import { type App, Modal, Notice, Setting } from "obsidian";
|
||||
import type SurfSensePlugin from "./main";
|
||||
|
||||
/**
|
||||
* Read-only status panel. Mirrors what the settings tab used to embed inline,
|
||||
* but as a modal so it's reachable from the status bar / command palette.
|
||||
*
|
||||
* Subscribes to plugin status changes while open so the numbers stay live;
|
||||
* unsubscribes on close.
|
||||
*/
|
||||
/** Live status panel reachable from the status bar / command palette. */
|
||||
export class StatusModal extends Modal {
|
||||
private readonly plugin: SurfSensePlugin;
|
||||
private readonly onChange = (): void => this.render();
|
||||
|
|
@ -18,7 +12,7 @@ export class StatusModal extends Modal {
|
|||
}
|
||||
|
||||
onOpen(): void {
|
||||
this.titleEl.setText("SurfSense status");
|
||||
this.setTitle("Surfsense status");
|
||||
this.plugin.onStatusChange(this.onChange);
|
||||
this.render();
|
||||
}
|
||||
|
|
@ -67,10 +61,10 @@ export class StatusModal extends Modal {
|
|||
btn.setDisabled(true);
|
||||
try {
|
||||
await plugin.engine.maybeReconcile(true);
|
||||
new Notice("SurfSense: re-sync requested.");
|
||||
new Notice("Surfsense: re-sync requested.");
|
||||
} catch (err) {
|
||||
new Notice(
|
||||
`SurfSense: re-sync failed — ${(err as Error).message}`,
|
||||
`Surfsense: re-sync failed — ${(err as Error).message}`,
|
||||
);
|
||||
} finally {
|
||||
btn.setDisabled(false);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,12 @@
|
|||
import { Notice, TFile, type App, type CachedMetadata, type TAbstractFile } from "obsidian";
|
||||
import {
|
||||
type App,
|
||||
type CachedMetadata,
|
||||
type Debouncer,
|
||||
Notice,
|
||||
type TAbstractFile,
|
||||
TFile,
|
||||
debounce,
|
||||
} from "obsidian";
|
||||
import {
|
||||
AuthError,
|
||||
PermanentError,
|
||||
|
|
@ -20,10 +28,8 @@ import type {
|
|||
import { computeVaultFingerprint } from "./vault-identity";
|
||||
|
||||
/**
|
||||
* Owner of "what does the vault look like vs the server" reasoning.
|
||||
*
|
||||
* Start order: connect (or fall back to /health) → drain queue → reconcile →
|
||||
* subscribe events. Reconcile no-ops if last run was < RECONCILE_MIN_INTERVAL_MS ago.
|
||||
* Reconciles vault state with the server.
|
||||
* Start order: connect (or /health) → drain queue → reconcile → subscribe events.
|
||||
*/
|
||||
|
||||
export interface SyncEngineDeps {
|
||||
|
|
@ -59,7 +65,7 @@ const PENDING_DEBOUNCE_MS = 1500;
|
|||
export class SyncEngine {
|
||||
private readonly deps: SyncEngineDeps;
|
||||
private capabilities: string[] = [];
|
||||
private pendingMdEdits = new Map<string, ReturnType<typeof setTimeout>>();
|
||||
private pendingMdEdits = new Map<string, Debouncer<[], void>>();
|
||||
/** Consecutive reconciles that found no work; powers the adaptive interval. */
|
||||
private idleReconcileStreak = 0;
|
||||
/** 2^streak is capped at this value (e.g. 8 → max ×8 backoff). */
|
||||
|
|
@ -89,7 +95,7 @@ export class SyncEngine {
|
|||
|
||||
const settings = this.deps.getSettings();
|
||||
if (!settings.searchSpaceId) {
|
||||
// No target yet — bare /health probe still surfaces auth/network errors.
|
||||
// No target yet — /health still surfaces auth/network errors.
|
||||
try {
|
||||
const health = await this.deps.apiClient.health();
|
||||
this.applyHealth(health);
|
||||
|
|
@ -102,8 +108,7 @@ export class SyncEngine {
|
|||
}
|
||||
|
||||
// Re-announce so the backend sees the latest vault_name + last_connect_at.
|
||||
// flushQueue owns the connectorId gate, so a failed connect here still
|
||||
// leaves the queue stable for the next trigger.
|
||||
// flushQueue gates on connectorId, so a failed connect leaves the queue intact.
|
||||
await this.ensureConnected();
|
||||
|
||||
await this.flushQueue();
|
||||
|
|
@ -112,12 +117,8 @@ export class SyncEngine {
|
|||
}
|
||||
|
||||
/**
|
||||
* (Re)register the vault with the server.
|
||||
*
|
||||
* Always trusts the server's response: when fingerprint dedup routes
|
||||
* us to another device's connector, ``resp.vault_id`` may differ from
|
||||
* what we sent and we adopt it locally so future /sync calls land on
|
||||
* the right row.
|
||||
* (Re)register the vault. Adopts server's `vault_id` in case fingerprint
|
||||
* dedup routed us to an existing row from another device.
|
||||
*/
|
||||
async ensureConnected(): Promise<void> {
|
||||
const settings = this.deps.getSettings();
|
||||
|
|
@ -168,7 +169,7 @@ export class SyncEngine {
|
|||
if (this.isExcluded(file.path, settings)) return;
|
||||
this.resetIdleStreak();
|
||||
if (this.isMarkdown(file)) {
|
||||
// Defer to metadataCache.changed so payload fields are fresh.
|
||||
// Wait for metadataCache.changed so the payload sees fresh metadata.
|
||||
this.scheduleMdUpsert(file.path);
|
||||
return;
|
||||
}
|
||||
|
|
@ -203,25 +204,30 @@ export class SyncEngine {
|
|||
const settings = this.deps.getSettings();
|
||||
if (this.isExcluded(file.path, settings)) return;
|
||||
if (!this.isMarkdown(file)) return;
|
||||
// Cancel any deferred upsert and enqueue with fresh metadata now.
|
||||
// Metadata is fresh now — cancel the deferred upsert and enqueue immediately.
|
||||
const pending = this.pendingMdEdits.get(file.path);
|
||||
if (pending) {
|
||||
clearTimeout(pending);
|
||||
pending.cancel();
|
||||
this.pendingMdEdits.delete(file.path);
|
||||
}
|
||||
this.deps.queue.enqueueUpsert(file.path);
|
||||
}
|
||||
|
||||
private scheduleMdUpsert(path: string): void {
|
||||
const existing = this.pendingMdEdits.get(path);
|
||||
if (existing) clearTimeout(existing);
|
||||
this.pendingMdEdits.set(
|
||||
path,
|
||||
setTimeout(() => {
|
||||
this.pendingMdEdits.delete(path);
|
||||
this.deps.queue.enqueueUpsert(path);
|
||||
}, PENDING_DEBOUNCE_MS),
|
||||
);
|
||||
let pending = this.pendingMdEdits.get(path);
|
||||
if (!pending) {
|
||||
// resetTimer: true → each edit pushes the upsert out by another PENDING_DEBOUNCE_MS.
|
||||
pending = debounce(
|
||||
() => {
|
||||
this.pendingMdEdits.delete(path);
|
||||
this.deps.queue.enqueueUpsert(path);
|
||||
},
|
||||
PENDING_DEBOUNCE_MS,
|
||||
true,
|
||||
);
|
||||
this.pendingMdEdits.set(path, pending);
|
||||
}
|
||||
pending();
|
||||
}
|
||||
|
||||
// ---- queue draining ---------------------------------------------------
|
||||
|
|
@ -256,8 +262,7 @@ export class SyncEngine {
|
|||
const retry: QueueItem[] = [];
|
||||
const dropped: QueueItem[] = [];
|
||||
|
||||
// Renames first so paths line up server-side before content upserts.
|
||||
// Per-item server errors go to retry; "missing" is treated as success.
|
||||
// Renames first so paths line up before content upserts.
|
||||
if (renames.length > 0) {
|
||||
try {
|
||||
const resp = await this.deps.apiClient.renameBatch({
|
||||
|
|
@ -309,9 +314,9 @@ export class SyncEngine {
|
|||
if (upserts.length > 0) {
|
||||
const payloads: NotePayload[] = [];
|
||||
for (const item of upserts) {
|
||||
const file = this.deps.app.vault.getAbstractFileByPath(item.path);
|
||||
if (!file || !isTFile(file)) {
|
||||
// File vanished; treat as ack (delete will follow if user removed it).
|
||||
const file = this.deps.app.vault.getFileByPath(item.path);
|
||||
if (!file) {
|
||||
// Vanished — ack now; the delete event will follow if needed.
|
||||
acked.push(item);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -332,7 +337,7 @@ export class SyncEngine {
|
|||
vaultId: settings.vaultId,
|
||||
notes: payloads,
|
||||
});
|
||||
// Per-note failures retry; the queue's maxAttempts eventually drops poison pills.
|
||||
// Per-note failures retry; queue maxAttempts drops poison pills.
|
||||
const failed = new Set(resp.failed);
|
||||
for (const item of upserts) {
|
||||
if (retry.find((r) => r === item)) continue;
|
||||
|
|
@ -360,9 +365,8 @@ export class SyncEngine {
|
|||
}
|
||||
|
||||
private async buildBinaryPayload(file: TFile, vaultId: string): Promise<NotePayload> {
|
||||
// Plain attachments don't go through buildNotePayload (no markdown
|
||||
// metadata to extract). We still need a stable hash + file stat so
|
||||
// the backend can de-dupe and the manifest diff still works.
|
||||
// Attachments skip buildNotePayload (no markdown metadata) but still
|
||||
// need hash + stat so the server can de-dupe and manifest diff works.
|
||||
const buf = await this.deps.app.vault.readBinary(file);
|
||||
const digest = await crypto.subtle.digest("SHA-256", buf);
|
||||
const hash = bufferToHex(digest);
|
||||
|
|
@ -396,10 +400,9 @@ export class SyncEngine {
|
|||
if (Date.now() - settings.lastReconcileAt < RECONCILE_MIN_INTERVAL_MS) return;
|
||||
}
|
||||
|
||||
// Re-handshake first so the server sees this device's current
|
||||
// fingerprint. If the vault grew since last connect and now
|
||||
// matches another device's row, the server merges and routes us
|
||||
// to the survivor; subsequent /manifest call uses the adopted id.
|
||||
// Re-handshake first: if the vault grew enough to match another
|
||||
// device's fingerprint, the server merges and routes us to the
|
||||
// survivor row, which the /manifest call below then uses.
|
||||
await this.ensureConnected();
|
||||
const refreshed = this.deps.getSettings();
|
||||
if (!refreshed.connectorId) return;
|
||||
|
|
@ -421,17 +424,10 @@ export class SyncEngine {
|
|||
}
|
||||
|
||||
/**
|
||||
* Compare local vault to server manifest and enqueue diffs.
|
||||
*
|
||||
* Performance: short-circuits on `mtime + size` for every file. We trust the
|
||||
* pair as a "no change" signal because (a) content edits move mtime, and
|
||||
* (b) same-mtime/different-content requires deliberate filesystem trickery.
|
||||
* False positives (mtime moved, content identical) collapse to a no-op
|
||||
* upsert on the server via its `content_hash` check. Net effect: zero disk
|
||||
* reads on idle reconciles.
|
||||
*
|
||||
* Returns the number of items enqueued so the caller can drive the
|
||||
* adaptive backoff.
|
||||
* Diff local vault vs server manifest and enqueue work. Skips disk reads
|
||||
* on idle reconciles by short-circuiting on `mtime + size`; false positives
|
||||
* collapse to a no-op upsert via the server's `content_hash` check.
|
||||
* Returns the enqueued count to drive adaptive backoff.
|
||||
*/
|
||||
private diffAndQueue(
|
||||
settings: SyncEngineSettings,
|
||||
|
|
@ -454,7 +450,7 @@ export class SyncEngine {
|
|||
}
|
||||
const remoteMtimeMs = toMillis(remoteEntry.mtime);
|
||||
const mtimeMatches = file.stat.mtime <= remoteMtimeMs + 1000;
|
||||
// Older server rows lack `size`; treat as "unknown" → fall through to upsert.
|
||||
// Older server rows lack `size` — treat as unknown and re-upsert.
|
||||
const sizeMatches =
|
||||
typeof remoteEntry.size === "number" && file.stat.size === remoteEntry.size;
|
||||
if (mtimeMatches && sizeMatches) continue;
|
||||
|
|
@ -462,8 +458,7 @@ export class SyncEngine {
|
|||
enqueued++;
|
||||
}
|
||||
|
||||
// Remote-only → delete, but only if NOT a fresh tombstone (which
|
||||
// the queue will deliver) and NOT a path we already plan to upsert.
|
||||
// Remote-only → delete, unless a fresh tombstone is already in the queue.
|
||||
for (const path of Object.keys(remote)) {
|
||||
if (localPaths.has(path)) continue;
|
||||
const tombstone = settings.tombstones[path];
|
||||
|
|
@ -475,7 +470,7 @@ export class SyncEngine {
|
|||
return enqueued;
|
||||
}
|
||||
|
||||
/** Bump (idle) or reset (active) the streak; notify only when the cap-aware multiplier changes. */
|
||||
/** Bump (idle) or reset (active) the streak; notify only when the capped multiplier changes. */
|
||||
private updateIdleStreak(enqueued: number): void {
|
||||
const previousStreak = this.idleReconcileStreak;
|
||||
if (enqueued === 0) this.idleReconcileStreak++;
|
||||
|
|
@ -486,7 +481,7 @@ export class SyncEngine {
|
|||
if (cappedPrev !== cappedNow) this.deps.onReconcileBackoffChanged?.();
|
||||
}
|
||||
|
||||
/** Vault edit happened — drop back to the base interval immediately. */
|
||||
/** Vault edit — drop back to base interval immediately. */
|
||||
private resetIdleStreak(): void {
|
||||
if (this.idleReconcileStreak === 0) return;
|
||||
this.idleReconcileStreak = 0;
|
||||
|
|
@ -543,7 +538,7 @@ export class SyncEngine {
|
|||
}
|
||||
if (err instanceof PermanentError) {
|
||||
console.warn("SurfSense: permanent error, dropping batch", err);
|
||||
new Notice(`SurfSense: ${err.message}`);
|
||||
new Notice(`Surfsense: ${err.message}`);
|
||||
return "drop";
|
||||
}
|
||||
console.error("SurfSense: unknown error", err);
|
||||
|
|
@ -595,7 +590,7 @@ function formatRelative(ts: number): string {
|
|||
return `${Math.round(diff / 86_400_000)}d ago`;
|
||||
}
|
||||
|
||||
/** Manifest mtimes are Pydantic-serialised ISO strings; vault stats are epoch ms. Normalise to ms. */
|
||||
/** Manifest mtimes arrive as ISO strings, vault stats as epoch ms — normalise. */
|
||||
function toMillis(value: number | string | Date): number {
|
||||
if (typeof value === "number") return value;
|
||||
if (value instanceof Date) return value.getTime();
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"0.1.0": "1.4.0"
|
||||
"0.1.0": "1.5.4"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"0.1.0": "1.4.0"
|
||||
"0.1.0": "1.5.4"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue