Store all albums and images in the database after loading them from the configuration.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 14 Sep 2014 16:04:31 +0000 (18:04 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 14 Sep 2014 16:04:31 +0000 (18:04 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/data/Sone.java

index 8c1aeed..9e20c00 100644 (file)
@@ -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) {
index 1b76588..6df84df 100644 (file)
@@ -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<Sone> {
                                }
                        };
 
+       public static final Function<Sone, List<Album>> toAllAlbums = new Function<Sone, List<Album>>() {
+               @Override
+               public List<Album> apply(@Nullable Sone sone) {
+                       return (sone == null) ? Collections.<Album>emptyList() : FLATTENER.apply(
+                                       sone.getRootAlbum());
+               }
+       };
+
        /**
         * Returns the identity of this Sone.
         *