Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

---

## [1.16.19] — 2026-11-02

### Fixed
- **Two overlapping exports of one account, imported together, counted the rows they share twice.**
- **When:** the folder, or Choose CSV files, holds two exports of the same account that share dates, such as a May – mid-September and an August – October checking export. It happened on every import that reads them together: boot, Reload CSVs, Reconnect, Rebuild from your folder, Choose CSV files. Checking and savings always go into one account. A card does when both files have the same name: the folder picker browsers without the folder API use reads subfolders, so two `card.csv` files from monthly folders arrive together.
- **What it did:** on the samples, checking split into May 1 – Sep 15 and Aug 1 – Oct 20 (23 shared rows) gave 280 transactions instead of 257 in memory and `finlens-state.json`, while IndexedDB held 257. Every total counted the shared rows twice: net worth, cash flow, the Transactions KPIs and count. The second copy of a transfer stayed a plain withdrawal, deposit or card payment (detection skips an id it has already marked), so it counted as spending or income too. An edited row showed twice, and a bucket listed a linked transaction twice. A page reload kept it all, since boot loads `finlens-state.json` first; only a boot from IndexedDB didn't.
- **Cause:** both files give the shared rows the same ids (CLAUDE.md §10). `loadFiles()` collected every file's transactions, and `mergeImported()` added them all, while `DB.importTransactions()` skips an id it already holds. `master` has it too: its import appends each file's rows (280 in memory, 257 in IndexedDB on the same files).
- **Fix:** `mergeImported()` keeps one transaction per id, the first file's, which is the row IndexedDB stores. Same-day identical card rows keep their `_2`, `_3`: they're counted within each file, so both files give them the same ids, and an export with one more copy (a later export, made after another identical charge posted that day) adds only that one.
- **IndexedDB too:** its leftover-copy check ran file by file. With that later export read first, the earlier one then deleted the extra copy (`_3`) from the store, so memory had it and a boot from IndexedDB didn't. `DB.importTransactions()` now takes every id of the import (`importIds`, from `loadFiles()` through `importParsedCsv()`) and never removes one of them.
- **Already saved:** a `finlens-state.json` that holds a transaction twice is loaded with one copy of each (`loadStateFromFile()`), and saved again.
- **Unchanged:** importing the exports one after the other already worked, since the second replaces the shared rows. Last import still lists a later file's shared rows as "already imported".
- **Not covered:** two card exports with different names are two accounts (§18), so the rows they share have different ids and both stay. That's how FinLens tells cards apart; it isn't changed here.

### Docs
- **CLAUDE.md:** §1 version; §4.5 one transaction per id; §8 `mergeImported()`, `importParsedCsv()`; §10 overlapping exports of one account; §19 `DB.importTransactions()` keeps the import's ids.

---

## [1.16.18] — 2026-11-02

### Fixed
Expand Down
20 changes: 15 additions & 5 deletions CLAUDE.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> A zero-install, browser-native finance dashboard. Drop in your bank CSVs, get instant clarity on your money.

**Version:** v1.16.18  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None
**Version:** v1.16.19  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None

---

Expand Down Expand Up @@ -261,4 +261,4 @@ See [CHANGELOG.md](CHANGELOG.md) for the full release history.

---

*FinLens v1.16.18 — Built for one person's finances, designed to be useful for anyone's.*
*FinLens v1.16.19 — Built for one person's finances, designed to be useful for anyone's.*
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@
<div class="folder-banner-wrap" id="folderBanner" hidden></div>
<div class="content" id="content"></div>
</main>
<footer class="appfoot">v1.16.18 · FinLens</footer>
<footer class="appfoot">v1.16.19 · FinLens</footer>

<!-- side drawer: transaction detail, bill and plan forms (ui.js openDrawer) -->
<div class="drawer-scrim" id="drawerScrim" onclick="closeDrawer()" hidden></div>
Expand Down
34 changes: 30 additions & 4 deletions js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ async function loadStateFromFile() {
// getter into a plain value. Rebuild them exactly as DB.loadAll() does, or
// monthKey()/date comparisons throw or misbehave (Income, Trends, AI summary).
if (Array.isArray(loaded.transactions)) {
// One transaction per id (v1.16.19). Up to v1.16.18 two overlapping exports of one
// account imported together saved the rows they share twice (mergeImported()). One id
// is one CSV row in one account (CLAUDE.md §10), so the first copy is kept, and the file
// is saved again without the others.
const seen = new Set(), all = loaded.transactions.length;
loaded.transactions = loaded.transactions.filter(raw => { if (seen.has(raw.id)) return false; seen.add(raw.id); return true; });
if (loaded.transactions.length < all) {
console.log(`[FinLens] finlens-state.json held ${all - loaded.transactions.length} transaction${all - loaded.transactions.length === 1 ? '' : 's'} twice (the same id); one copy of each is kept`);
_saveStateDebounced(State);
}
const ovs = loaded.txOverrides || State.txOverrides || {};
// Rule flags come from the file's own rules: State only gets them after this returns.
const rules = Array.isArray(loaded.txRules) ? loaded.txRules : State.txRules;
Expand Down Expand Up @@ -787,7 +797,9 @@ function parseCsvFile(file, forcedKind) {
// logs the import and adds it to State.fileMeta. Returns the file's transactions;
// loadFiles() puts them in State.transactions. A failing database write is logged and the
// import carries on, so the transactions still reach memory and finlens-state.json.
async function importParsedCsv(p) {
// importIds: every id the files of this import give (loadFiles()); IndexedDB keeps them
// when it removes leftover copies (DB.importTransactions(), v1.16.19).
async function importParsedCsv(p, importIds) {
const { file, schema, kind, accountId, accountName, txs } = p;
// Initialise account in State (in-memory). Its name is always the default: a name
// you typed stays in State.accountLabels, and acctName() shows that first. (Older
Expand Down Expand Up @@ -822,7 +834,7 @@ async function importParsedCsv(p) {
initialBalance: State.manualBalances[accountId+'_initial'] != null ? Number(State.manualBalances[accountId+'_initial']) : null,
});

importResult = await DB.importTransactions(txs, accountId, schema.id);
importResult = await DB.importTransactions(txs, accountId, schema.id, importIds);

await DB.logImport({
filename: file.name,
Expand Down Expand Up @@ -927,10 +939,14 @@ async function loadFiles(fileList, assignments, opts = {}) {
// account, so with other ids. Its earlier rows are found before anything is written
// (v1.16.17), then leave their old account below.
const moves = await earlierCopies(read);
// Every id the files of this import give. Two overlapping exports of one account give the
// rows they share with the same id (§10): IndexedDB's leftover-copy check for one file must
// not delete a row another file of this import gives (v1.16.19).
const importIds = new Set(read.filter(p => p.schema && !p.problem).flatMap(p => p.txs.map(t => t.id)));
const fresh = [];
for (const p of read) {
if (!p.schema || p.problem) continue; // a file that gave no transactions creates no account
fresh.push(...await importParsedCsv(p));
fresh.push(...await importParsedCsv(p, importIds));
}
if (moves.size) await moveEarlierCopies(moves, read, fresh);
// The files' transactions join the loaded ones; none of the others is dropped (v1.16.3).
Expand Down Expand Up @@ -973,11 +989,21 @@ async function loadFiles(fileList, assignments, opts = {}) {
// id whose base is in the files but whose exact id isn't.
// - A kept transfer leg goes back to its values before detection (undoTransferDetection()),
// so loadFiles()'s detectTransfers() can pair it again, with a row just re-read too.
// - One transaction per id (v1.16.19). Two overlapping exports of one account (a September
// export and a September–October one, read together) give the rows they share with the
// same id: the id hashes the row and the account (CLAUDE.md §10), and a file's _2, _3 …
// are counted in that file alone, so its same-day copies get the same ids in both files.
// The first file's copy stays, as in IndexedDB, where the later files skip that id. Up to
// v1.16.18 both copies were kept, so the shared rows counted twice in every total, and the
// autosave wrote them twice to finlens-state.json. A loaded id held twice (a state file
// saved then) keeps one copy too.
async function mergeImported(loaded, fresh) {
const baseOf = (id) => id.replace(/_\d+$/, '');
const once = (list) => { const seen = new Set(); return list.filter(t => !seen.has(t.id) && !!seen.add(t.id)); };
fresh = once(fresh);
const ids = new Set(fresh.map(t => t.id));
const bases = new Set(fresh.map(t => baseOf(t.id)));
const kept = loaded.filter(t => !ids.has(t.id) && !(t.id !== baseOf(t.id) && bases.has(baseOf(t.id))));
const kept = once(loaded.filter(t => !ids.has(t.id) && !(t.id !== baseOf(t.id) && bases.has(baseOf(t.id)))));
// A transfer from a ≤v1.16.0 finlens-state.json doesn't record its CSV type and
// category; its IndexedDB row does, when this browser has one.
const known = (t) => t._originalType && Array.isArray(t._originalCategories) && t._originalCategories.length;
Expand Down
11 changes: 9 additions & 2 deletions js/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,16 @@ const DB = {
* such row). Same-day identical rows always appear together in a bank export, so the
* file is authoritative for how many copies of each of its transactions exist.
*
* importIds (optional, v1.16.19): every ID the files of this import give (loadFiles()).
* A row with one of them is never a leftover copy, so with two overlapping exports of one
* account read together, the one with fewer copies of a same-day row (exported before the
* last one posted) doesn't delete the copy the other file just added. Up to v1.16.18 it
* did when that file came second, and the browser database then held one row fewer than
* memory and finlens-state.json.
*
* Returns { inserted, skipped, removed, dateRangeMin, dateRangeMax, gapWarning }.
*/
async importTransactions(txArray, accountId, schemaId) {
async importTransactions(txArray, accountId, schemaId, importIds) {
if (!this._db || !txArray.length) {
return { inserted: 0, skipped: 0, removed: 0, dateRangeMin: null, dateRangeMax: null, gapWarning: null };
}
Expand Down Expand Up @@ -283,7 +290,7 @@ const DB = {
const batchIds = new Set(sorted.map(t => t.id));
const batchBases = new Set(sorted.map(t => baseOf(t.id)));
const stale = [...existingIds].filter(id =>
id !== baseOf(id) && !batchIds.has(id) && batchBases.has(baseOf(id)));
id !== baseOf(id) && !batchIds.has(id) && !(importIds && importIds.has(id)) && batchBases.has(baseOf(id)));
if (stale.length) {
removed = await new Promise((res) => {
const t = this._db.transaction('transactions', 'readwrite');
Expand Down
2 changes: 1 addition & 1 deletion js/views-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function _renderGeneralSettings(root) {
/* ---- About (the Theme row is gone: light only for now) ---- */
appendHtml(root,`<section class="panel" aria-labelledby="dispH">
<h2 id="dispH">About</h2>
<div class="set-row"><span class="t">Version</span><span class="v">FinLens v1.16.18</span></div>
<div class="set-row"><span class="t">Version</span><span class="v">FinLens v1.16.19</span></div>
</section>`);

/* ---- Anthropic API key ---- */
Expand Down