mirror of
https://github.com/readest/readest.git
synced 2026-11-30 03:13:39 +00:00
* feat(calibre): add a Check Readest status action that marks the results
The plugin could only tell you a book's cloud state as a side effect of
pushing it. "Check Readest status" runs the same planner over the
selected books without uploading anything, then records the answer as
calibre marks, so the book list shows it and `marked:readest_missing`
selects exactly the books that still need a push.
plan_push already produced the four states, so the classification is
shared rather than duplicated: PushWorker and the new StatusWorker both
derive from _CloudWorker, which pulls the server rows plus the storage
listing once and plans one book at a time. Marks are derived from the
cloud on every run and never stored, the same rule that keeps the push
free of machine-local state.
A push also marks what it pushed, otherwise marks left by an earlier
check would go stale the moment you uploaded something. merge_marks
replaces only the readest_ labels, so marks the user set by hand
survive a check.
Verified against a real calibre 8 install and library: the plugin loads,
_plan_for classifies real books, refresh_ids repaints and tolerates ids
filtered out of the current view, and calibre renders an icon for each
of the four custom labels.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(calibre): take the plugin version from the app's package.json
PLUGIN_VERSION was a committed (0, 1, 0) placeholder that release.yml
rewrote at release time. Anything built locally therefore installed into
calibre as "Readest Sync (0, 1, 0)", which is what Preferences > Plugins
then reports, and the placeholder drifted further with every app bump.
Make apps/readest-app/package.json the source of truth for local builds
too. It already is for releases: release.yml's release_version is
require('./apps/readest-app/package.json').version, so `make zip` and CI
stamp the same value and cannot disagree. The literal stays in
__init__.py because the plugin ships as a standalone zip with no
package.json to read.
sync_version.py writes only when the version has drifted, so it is an
order-only prerequisite of the zip and never forces a rebuild. A unit
test asserts the committed literal matches package.json, so the drift
fails the suite instead of reaching a user's calibre.
Verified with a real calibre 8: `make zip` produces
Readest-0.11.20.calibre-plugin.zip and calibre-customize reports
Readest Sync (0, 11, 20).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* perf(calibre): look blobs up per book when the selection is small
Checking a single book took 25s. Timed against a real account, the whole
cost was setup: pull_books 3.2s, then 22.4s paging the storage listing.
That listing costs a request per page whatever the selection size, so a
one-book check paid for all 1580 files.
The listing endpoint costs about a second per request almost regardless
of rows returned (1 file 0.93s, 100 files 1.23s), and a single-hash
lookup costs about the same. So page 1 now decides: if the listing is
longer than the selection, ask storage about each book instead, cached
per run. plan_push takes a callable for that and consults it last, after
the free checks, so a book already headed for new/replace never spends a
request.
One book now takes 4.8s and 5 books 6.8s, while a 40-book run still
takes the listing and is unchanged at 24s.
LIST_PAGE_SIZE also asks for 1000 rather than 100. Servers clamp it and
report totalPages for the size they actually served, so paging stays
correct today and gets faster on its own if the cap is ever raised.
Per-book lookups key on files.book_hash. Checked against a real account:
of 1580 files the 50 with a null book_hash are all dictionary replicas,
never book blobs.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* perf(storage): raise the file listing page cap to 1000
A listing request costs about a second almost regardless of how many
rows it returns (measured: 1 file 0.93s, 100 files 1.23s), so a client
walking the whole account pays per page. At the old cap of 100 an
account with 1530 files took 16 requests and 22s; at 1000 it takes 2.
Bumping the number alone would break the endpoint. The group expansion
that pulls a book's sibling files runs `.in('book_hash', hashes)` with
one entry per distinct hash on the page, and Supabase renders that into
the request's query string, so a full page at the new cap would be tens
of kilobytes of URL. Send it in batches of 100 instead, in parallel, and
merge as before. Worst case is about 21 subrequests per listing request,
well inside the Workers limit.
resolvePageSize also floors the size at 1, so a negative pageSize can no
longer produce an inverted .range() and a 500.
The in-app Storage Manager asks for 20 and is unaffected. The calibre
plugin already asks for 1000 and paginates off the totalPages the server
reports, so it speeds up as soon as this deploys and stays correct
against servers that still clamp.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
import os
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
from sync_version import app_version, plugin_version, sync # noqa: E402
|
|
|
|
|
|
class PluginVersionTest(unittest.TestCase):
|
|
def test_committed_version_matches_the_app(self):
|
|
# The zip ships PLUGIN_VERSION as a literal, so a stale value means
|
|
# every local build installs into calibre under the wrong version.
|
|
# release.yml stamps releases from this same package.json.
|
|
self.assertEqual(plugin_version(), app_version())
|
|
|
|
def test_app_version_is_a_three_part_tuple(self):
|
|
version = app_version()
|
|
self.assertEqual(len(version), 3)
|
|
self.assertTrue(all(isinstance(part, int) for part in version))
|
|
|
|
|
|
class SyncTest(unittest.TestCase):
|
|
def write(self, body):
|
|
fd, path = tempfile.mkstemp(suffix='.py')
|
|
os.close(fd)
|
|
with open(path, 'w', encoding='utf-8') as f:
|
|
f.write(body)
|
|
self.addCleanup(os.unlink, path)
|
|
return path
|
|
|
|
def test_rewrites_a_stale_version(self):
|
|
path = self.write("NAME = 'x'\nPLUGIN_VERSION = (0, 1, 0)\nOTHER = 1\n")
|
|
self.assertTrue(sync(path, (0, 11, 20)))
|
|
self.assertEqual(plugin_version(path), (0, 11, 20))
|
|
|
|
def test_is_idempotent(self):
|
|
path = self.write('PLUGIN_VERSION = (0, 11, 20)\n')
|
|
self.assertFalse(sync(path, (0, 11, 20)))
|
|
|
|
def test_leaves_the_rest_of_the_file_alone(self):
|
|
path = self.write(
|
|
"HEAD = 1\nPLUGIN_VERSION = (0, 1, 0)\nTAIL = 'PLUGIN_VERSION = (9, 9, 9)'\n"
|
|
)
|
|
sync(path, (1, 2, 3))
|
|
with open(path, encoding='utf-8') as f:
|
|
body = f.read()
|
|
self.assertIn('HEAD = 1', body)
|
|
self.assertIn("TAIL = 'PLUGIN_VERSION = (9, 9, 9)'", body)
|
|
self.assertIn('PLUGIN_VERSION = (1, 2, 3)', body)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|