Skip to content

Commit

Permalink
Allow offline usage for POIs #1169 - Added yesterday timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Jun 11, 2020
1 parent e9d38c0 commit 38b55fc
Showing 1 changed file with 3 additions and 33 deletions.
36 changes: 3 additions & 33 deletions IsraelHiking.API/Services/Poi/OsmPointsOfInterestAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,10 @@ public async Task<PointOfInterestExtended> UpdatePointOfInterest(PointOfInterest
AddTagsByIcon(completeOsmGeo.Tags, pointOfInterest.Icon);
}
RemoveEmptyTags(completeOsmGeo.Tags);
if (AreTagsCollectionEqual(oldTags, completeOsmGeo.Tags.ToArray()))
if (Enumerable.SequenceEqual(oldTags, completeOsmGeo.Tags.ToArray()))
{
return pointOfInterest;
}

var changesetId = await osmGateway.CreateChangeset($"Updated {pointOfInterest.Title} using IsraelHiking.osm.org.il");
await osmGateway.UpdateElement(changesetId, completeOsmGeo);
await osmGateway.CloseChangeset(changesetId);
Expand All @@ -277,22 +276,6 @@ public async Task<PointOfInterestExtended> UpdatePointOfInterest(PointOfInterest
return await FeatureToExtendedPoi(featureToReturn, language);
}

private bool AreTagsCollectionEqual(Tag[] oldTags, Tag[] currentTags)
{
if (oldTags.Length != currentTags.Length)
{
return false;
}
foreach (var currentTag in currentTags)
{
if (!oldTags.Any(t => t.Equals(currentTag)))
{
return false;
}
}
return true;
}

/// <inheritdoc />
public override async Task<List<Feature>> GetPointsForIndexing()
{
Expand Down Expand Up @@ -363,22 +346,9 @@ private async Task<Feature> UpdateElasticSearch(ICompleteOsmGeo osm, string name
feature.Geometry = featureFromDb.Geometry;
}
}

// set last modified date to be yesterday so that rebuild will override it and client will get it on next update.
feature.Attributes.AddOrUpdate(FeatureAttributes.POI_LAST_MODIFIED, DateTime.Now.AddDays(-1));
await _elasticSearchGateway.UpdatePointsOfInterestData(new List<Feature> { feature });
foreach (var language in Languages.Array)
{
var title = feature.Attributes.GetWikipediaTitle(language);
if (string.IsNullOrWhiteSpace(title))
{
continue;
}
var pageFetaure = await _wikipediaGateway.GetByPageTitle(title, language);
if (pageFetaure == null)
{
continue;
}
await _elasticSearchGateway.DeletePointOfInterestById(pageFetaure.Attributes[FeatureAttributes.ID].ToString(), Sources.WIKIPEDIA);
}
return feature;
}

Expand Down

0 comments on commit 38b55fc

Please sign in to comment.