Changeset 15426 in josm for trunk


Ignore:
Timestamp:
2019-10-05T23:38:29+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #13890 - improve performance of "Upload selection" checks

Location:
trunk
Files:
3 edited

Legend:

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

    r15404 r15426  
    6868            setEnabled(false);
    6969        }
    70         if (isEnabled() && selection.stream().noneMatch(OsmPrimitive::isModified)) {
     70        if (isEnabled() && selection.parallelStream().noneMatch(OsmPrimitive::isModified)) {
    7171            setEnabled(false);
    7272        }
     
    7474
    7575    protected Set<OsmPrimitive> getDeletedPrimitives(DataSet ds) {
    76         return ds.allPrimitives().stream()
     76        return ds.allPrimitives().parallelStream()
    7777                .filter(p -> p.isDeleted() && !p.isNew() && p.isVisible() && p.isModified())
    7878                .collect(Collectors.toSet());
     
    8080
    8181    protected Set<OsmPrimitive> getModifiedPrimitives(Collection<OsmPrimitive> primitives) {
    82         return primitives.stream()
     82        return primitives.parallelStream()
    8383                .filter(p -> p.isNewOrUndeleted() || (p.isModified() && !p.isIncomplete()))
    8484                .collect(Collectors.toSet());
     
    124124     */
    125125    protected boolean hasPrimitivesToDelete(Collection<OsmPrimitive> primitives) {
    126         for (OsmPrimitive p: primitives) {
    127             if (p.isDeleted() && p.isModified() && !p.isNew())
    128                 return true;
    129         }
    130         return false;
     126        return primitives.parallelStream().anyMatch(p -> p.isDeleted() && p.isModified() && !p.isNew());
    131127    }
    132128
     
    240236
    241237        /**
    242          *
     238         * Constructs a new {@code DeletedParentsChecker}.
    243239         * @param layer the data layer for which a collection of selected primitives is uploaded
    244240         * @param toUpload the collection of primitives to upload
     
    278274         */
    279275        protected Set<OsmPrimitive> getPrimitivesToCheckForParents() {
    280             return toUpload.stream().filter(p -> p.isDeleted() && !p.isNewOrUndeleted()).collect(Collectors.toSet());
     276            return toUpload.parallelStream().filter(p -> p.isDeleted() && !p.isNewOrUndeleted()).collect(Collectors.toSet());
    281277        }
    282278
     
    291287                    OsmPrimitive current = toCheck.pop();
    292288                    synchronized (this) {
    293                         reader = new OsmServerBackreferenceReader(current);
     289                        reader = new OsmServerBackreferenceReader(current).setAllowIncompleteParentWays(true);
    294290                    }
    295291                    getProgressMonitor().subTask(tr("Reading parents of ''{0}''", current.getDisplayName(DefaultNameFormatter.getInstance())));
     
    302298                    for (OsmPrimitive p: ds.allPrimitives()) {
    303299                        if (canceled) return;
     300                        if (p instanceof Node || (p instanceof Way && !(current instanceof Node))) continue;
    304301                        OsmPrimitive myDeletedParent = layer.data.getPrimitiveById(p);
    305302                        // our local dataset includes a deleted parent of a primitive we want
  • trunk/src/org/openstreetmap/josm/io/OsmServerBackreferenceReader.java

    r14214 r15426  
    4242    /** true if this reader should complete incomplete primitives */
    4343    private boolean readFull;
     44    /** true if this reader should allow incomplete parent ways */
     45    private boolean allowIncompleteParentWays;
    4446
    4547    /**
     
    113115
    114116    /**
    115      * Set true if this reader should reads immediate children of referring primitives too. False, otherweise.
    116      *
    117      * @param readFull true if this reader should reads immediate children of referring primitives too. False, otherweise.
    118      */
    119     public void setReadFull(boolean readFull) {
     117     * Set true if this reader should reads immediate children of referring primitives too. False, otherwise.
     118     *
     119     * @param readFull true if this reader should reads immediate children of referring primitives too. False, otherwise.
     120     * @return {@code this}, for easy chaining
     121     * @since 15426
     122     */
     123    public OsmServerBackreferenceReader setReadFull(boolean readFull) {
    120124        this.readFull = readFull;
     125        return this;
     126    }
     127
     128    /**
     129     * Determines if this reader allows to return incomplete parent ways of a node.
     130     * @return {@code true} if this reader allows to return incomplete parent ways of a node
     131     * @since 15426
     132     */
     133    public boolean isAllowIncompleteParentWays() {
     134        return allowIncompleteParentWays;
     135    }
     136
     137    /**
     138     * Sets whether this reader allows to return incomplete parent ways of a node.
     139     * @param allowIncompleteWays {@code true} if this reader allows to return incomplete parent ways of a node
     140     * @return {@code this}, for easy chaining
     141     * @since 15426
     142     */
     143    public OsmServerBackreferenceReader setAllowIncompleteParentWays(boolean allowIncompleteWays) {
     144        this.allowIncompleteParentWays = allowIncompleteWays;
     145        return this;
    121146    }
    122147
     
    175200     * <ul>
    176201     *   <li>if this reader reads referers for a {@link org.openstreetmap.josm.data.osm.Node}, referring ways are always
    177      *     read individually from the server</li>
     202     *     read fully, unless {@link #setAllowIncompleteParentWays(boolean)} is set to true.</li>
    178203     *   <li>if this reader reads referers for an {@link Way} or a {@link Relation}, referring relations
    179204     *    are only read fully if {@link #setReadFull(boolean)} is set to true.</li>
     
    191216        try {
    192217            Collection<Way> waysToCheck = new ArrayList<>(ds.getWays());
    193             if (isReadFull() || primitiveType == OsmPrimitiveType.NODE) {
     218            if (isReadFull() || (primitiveType == OsmPrimitiveType.NODE && !isAllowIncompleteParentWays())) {
    194219                for (Way way: waysToCheck) {
    195220                    if (!way.isNew() && way.hasIncompleteNodes()) {
  • trunk/test/functional/org/openstreetmap/josm/io/OsmServerBackreferenceReaderTest.java

    r14190 r15426  
    242242        assertNotNull(w);
    243243
    244         OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(n);
    245         reader.setReadFull(false);
    246         DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);
     244        DataSet referers = new OsmServerBackreferenceReader(n).setReadFull(false).parseOsm(NullProgressMonitor.INSTANCE);
    247245        printNumberOfPrimitives(referers);
    248246
     
    298296        assertNotNull(n);
    299297
    300         OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(n);
    301         reader.setReadFull(true);
    302         DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);
     298        DataSet referers = new OsmServerBackreferenceReader(n).setReadFull(true).parseOsm(NullProgressMonitor.INSTANCE);
    303299        printNumberOfPrimitives(referers);
    304300
     
    349345        //
    350346
    351         OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(w);
    352         reader.setReadFull(false);
    353         DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);
     347        DataSet referers = new OsmServerBackreferenceReader(w).setReadFull(false).parseOsm(NullProgressMonitor.INSTANCE);
    354348        printNumberOfPrimitives(referers);
    355349
     
    394388        //
    395389
    396         OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(w);
    397         reader.setReadFull(true);
    398         DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);
     390        DataSet referers = new OsmServerBackreferenceReader(w).setReadFull(true).parseOsm(NullProgressMonitor.INSTANCE);
    399391        assertEquals(6, referers.getWays().size());  // 6 ways referred by two relations
    400392        for (Way w1 : referers.getWays()) {
     
    434426        //
    435427
    436         OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(r);
    437         reader.setReadFull(false);
    438         DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);
     428        DataSet referers = new OsmServerBackreferenceReader(r).setReadFull(false).parseOsm(NullProgressMonitor.INSTANCE);
    439429        printNumberOfPrimitives(referers);
    440430
     
    554544        //
    555545
    556         OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(r);
    557         reader.setReadFull(true);
    558         DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);
     546        DataSet referers = new OsmServerBackreferenceReader(r).setReadFull(true).parseOsm(NullProgressMonitor.INSTANCE);
    559547
    560548        r = lookupRelation(referers, 6);
Note: See TracChangeset for help on using the changeset viewer.