From 51341976b36a42fec8fb093ef4079e4b618844f9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 14 Sep 2014 18:04:31 +0200 Subject: [PATCH] Store all albums and images in the database after loading them from the configuration. --- src/main/java/net/pterodactylus/sone/core/Core.java | 7 +++++++ src/main/java/net/pterodactylus/sone/data/Sone.java | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 8c1aeed..9e20c00 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -25,6 +25,7 @@ import static com.google.common.primitives.Longs.tryParse; import static java.lang.String.format; import static java.util.logging.Level.WARNING; import static net.pterodactylus.sone.data.Sone.LOCAL_SONE_FILTER; +import static net.pterodactylus.sone.data.Sone.toAllAlbums; import java.net.MalformedURLException; import java.util.ArrayList; @@ -1193,6 +1194,12 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, sone.getRootAlbum().addAlbum(album); } soneInserters.get(sone).setLastInsertFingerprint(lastInsertFingerprint); + for (Album album : toAllAlbums.apply(sone)) { + database.storeAlbum(album); + for (Image image : album.getImages()) { + database.storeImage(image); + } + } } synchronized (knownSones) { for (String friend : friends) { diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index 1b76588..6df84df 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -23,6 +23,7 @@ import static net.pterodactylus.sone.data.Album.FLATTENER; import static net.pterodactylus.sone.data.Album.IMAGES; import java.util.Collection; +import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Set; @@ -182,6 +183,14 @@ public interface Sone extends Identified, Fingerprintable, Comparable { } }; + public static final Function> toAllAlbums = new Function>() { + @Override + public List apply(@Nullable Sone sone) { + return (sone == null) ? Collections.emptyList() : FLATTENER.apply( + sone.getRootAlbum()); + } + }; + /** * Returns the identity of this Sone. * -- 2.7.4