Changeset 4094 in josm for trunk


Ignore:
Timestamp:
2011-05-24T00:38:25+02:00 (14 years ago)
Author:
bastiK
Message:

applied #5293 (patch by lordsutch) - Fix: Download parent ways/relations unnecessarily downloads nodes repeatedly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadReferrersTask.java

    r3720 r4094  
    88import java.text.MessageFormat;
    99import java.util.Collection;
     10import java.util.Set;
     11import java.util.HashSet;
    1012import java.util.HashMap;
    1113import java.util.Map;
     
    1820import org.openstreetmap.josm.data.osm.DataSet;
    1921import org.openstreetmap.josm.data.osm.DataSetMerger;
     22import org.openstreetmap.josm.data.osm.Node;
    2023import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2124import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    193196        }
    194197        Collection<Way> ways = ds.getWays();
     198
    195199        DataSetMerger merger;
    196200        if (!ways.isEmpty()) {
    197             reader = new MultiFetchServerObjectReader();
     201            Set<Node> nodes = new HashSet<Node>();
    198202            for (Way w: ways) {
    199                 ((MultiFetchServerObjectReader)reader).append(w.getNodes());
    200             }
    201             DataSet wayNodes = reader.parseOsm(progressMonitor.createSubTaskMonitor(1, false));
    202             synchronized(this) { // avoid race condition in cancel()
    203                 reader = null;
    204             }
    205             merger = new DataSetMerger(ds, wayNodes);
    206             merger.merge();
     203                // Ensure each node is only listed once
     204                nodes.addAll(w.getNodes());
     205            }
     206            // Don't retrieve any nodes we've already grabbed
     207            nodes.removeAll(targetLayer.data.getNodes());
     208            if (!nodes.isEmpty()) {
     209                reader = new MultiFetchServerObjectReader();
     210                ((MultiFetchServerObjectReader)reader).append(nodes);
     211                DataSet wayNodes = reader.parseOsm(progressMonitor.createSubTaskMonitor(1, false));
     212                synchronized(this) { // avoid race condition in cancel()
     213                    reader = null;
     214                }
     215                merger = new DataSetMerger(ds, wayNodes);
     216                merger.merge();
     217            }
    207218        }
    208219        merger = new DataSetMerger(parents, ds);
Note: See TracChangeset for help on using the changeset viewer.