From efa3c511f39ab1432675e3b75b9b7b32d579f1c3 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Fri, 10 Aug 2018 17:33:40 +0200 Subject: [PATCH] Remote: fix missing cover (try 1) --- .../nikiroo/fanfix/library/BasicLibrary.java | 28 +++++++++++----- .../nikiroo/fanfix/library/CacheLibrary.java | 33 ++++++++++++------- .../nikiroo/fanfix/library/LocalLibrary.java | 15 ++++++--- .../nikiroo/fanfix/library/RemoteLibrary.java | 18 +++++++--- 4 files changed, 64 insertions(+), 30 deletions(-) diff --git a/src/be/nikiroo/fanfix/library/BasicLibrary.java b/src/be/nikiroo/fanfix/library/BasicLibrary.java index 350a8ca..206e80f 100644 --- a/src/be/nikiroo/fanfix/library/BasicLibrary.java +++ b/src/be/nikiroo/fanfix/library/BasicLibrary.java @@ -135,19 +135,29 @@ abstract public class BasicLibrary { * Invalidate the {@link Story} cache (when the content should be re-read * because it was changed). */ - protected void invalidateInfo() { - invalidateInfo(null); + protected void deleteInfo() { + deleteInfo(null); } /** - * Invalidate the {@link Story} cache (when the content should be re-read - * because it was changed). + * Invalidate the {@link Story} cache (when the content is removed). + *

+ * All the cache can be deleted if NULL is passed as meta. * * @param luid - * the luid of the {@link Story} to clear from the cache, or NULL + * the LUID of the {@link Story} to clear from the cache, or NULL * for all stories */ - protected abstract void invalidateInfo(String luid); + protected abstract void deleteInfo(String luid); + + /** + * Invalidate the {@link Story} cache (when the content has changed, but we + * already have it) with the new given meta. + * + * @param meta + * the {@link Story} to clear from the cache + */ + protected abstract void updateInfo(MetaData meta); /** * Return the next LUID that can be used. @@ -521,9 +531,9 @@ abstract public class BasicLibrary { delete(luid); } - doSave(story, pg); + story = doSave(story, pg); - invalidateInfo(luid); + updateInfo(story.getMeta()); return story; } @@ -539,7 +549,7 @@ abstract public class BasicLibrary { */ public synchronized void delete(String luid) throws IOException { doDelete(luid); - invalidateInfo(luid); + deleteInfo(luid); } /** diff --git a/src/be/nikiroo/fanfix/library/CacheLibrary.java b/src/be/nikiroo/fanfix/library/CacheLibrary.java index ee22e34..ee2db3f 100644 --- a/src/be/nikiroo/fanfix/library/CacheLibrary.java +++ b/src/be/nikiroo/fanfix/library/CacheLibrary.java @@ -83,8 +83,8 @@ public class CacheLibrary extends BasicLibrary { if (!isCached(luid)) { try { cacheLib.imprt(lib, luid, pgImport); + updateInfo(cacheLib.getInfo(luid)); pgImport.done(); - invalidateInfo(luid); } catch (IOException e) { Instance.getTraceHandler().error(e); } @@ -123,24 +123,33 @@ public class CacheLibrary extends BasicLibrary { } @Override - protected void invalidateInfo(String luid) { + protected void updateInfo(MetaData meta) { + if (meta != null) { + for (int i = 0; i < metas.size(); i++) { + if (metas.get(i).getLuid().equals(meta.getLuid())) { + metas.set(i, meta); + } + } + } + + cacheLib.updateInfo(meta); + lib.updateInfo(meta); + } + + @Override + protected void deleteInfo(String luid) { if (luid == null) { metas = null; } else if (metas != null) { - MetaData meta = lib.getInfo(luid); for (int i = 0; i < metas.size(); i++) { if (metas.get(i).getLuid().equals(luid)) { metas.remove(i--); } } - - if (meta != null) { - metas.add(meta); - } } - cacheLib.invalidateInfo(luid); - lib.invalidateInfo(luid); + cacheLib.deleteInfo(luid); + lib.deleteInfo(luid); } @Override @@ -160,7 +169,7 @@ public class CacheLibrary extends BasicLibrary { story = lib.save(story, luid, pgLib); story = cacheLib.save(story, story.getMeta().getLuid(), pgCacheLib); - invalidateInfo(story.getMeta().getLuid()); + updateInfo(story.getMeta()); return story; } @@ -233,7 +242,7 @@ public class CacheLibrary extends BasicLibrary { public void clearFromCache(String luid) throws IOException { if (isCached(luid)) { cacheLib.delete(luid); - invalidateInfo(luid); + deleteInfo(luid); } } @@ -252,7 +261,7 @@ public class CacheLibrary extends BasicLibrary { Story story = lib.imprt(url, pgImprt); cacheLib.save(story, story.getMeta().getLuid(), pgCache); - invalidateInfo(story.getMeta().getLuid()); + updateInfo(story.getMeta()); pg.done(); return story; diff --git a/src/be/nikiroo/fanfix/library/LocalLibrary.java b/src/be/nikiroo/fanfix/library/LocalLibrary.java index 275926c..54ad1d6 100644 --- a/src/be/nikiroo/fanfix/library/LocalLibrary.java +++ b/src/be/nikiroo/fanfix/library/LocalLibrary.java @@ -127,7 +127,12 @@ public class LocalLibrary extends BasicLibrary { } @Override - protected synchronized void invalidateInfo(String luid) { + protected synchronized void updateInfo(MetaData meta) { + deleteInfo(); + } + + @Override + protected void deleteInfo(String luid) { stories = null; sourceCovers = new HashMap(); } @@ -189,7 +194,7 @@ public class LocalLibrary extends BasicLibrary { } } - invalidateInfo(); + deleteInfo(); } @Override @@ -261,7 +266,7 @@ public class LocalLibrary extends BasicLibrary { pg.add(1); } - invalidateInfo(); + deleteInfo(); pg.done(); return; } @@ -269,7 +274,7 @@ public class LocalLibrary extends BasicLibrary { super.imprt(other, luid, pg); - invalidateInfo(); + deleteInfo(); } /** @@ -404,7 +409,7 @@ public class LocalLibrary extends BasicLibrary { * {@link LocalLibrary#baseDir}. *

* Will use a cached list when possible (see - * {@link BasicLibrary#invalidateInfo()}). + * {@link BasicLibrary#deleteInfo()}). * * @param pg * the optional {@link Progress} diff --git a/src/be/nikiroo/fanfix/library/RemoteLibrary.java b/src/be/nikiroo/fanfix/library/RemoteLibrary.java index 5052fa2..44d39ad 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibrary.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibrary.java @@ -233,10 +233,14 @@ public class RemoteLibrary extends BasicLibrary { }.connect(); // because the meta changed: - invalidateInfo(luidSaved[0]); - MetaData meta = getInfo(luidSaved[0]); - meta.setCover(story.getMeta().getCover()); + if (story.getMeta().getClass() != null) { + // If already available locally: + meta.setCover(story.getMeta().getCover()); + } else { + // If required: + meta.setCover(getCover(meta.getLuid())); + } story.setMeta(meta); pg.done(); @@ -411,7 +415,13 @@ public class RemoteLibrary extends BasicLibrary { } @Override - protected void invalidateInfo(String luid) { + protected void updateInfo(MetaData meta) { + // Will be taken care of directly server side + } + + @Override + protected void deleteInfo(String luid) { + // Will be taken care of directly server side } // The following methods are only used by Save and Delete in BasicLibrary: -- 2.27.0