Skip to content

Commit

Permalink
Improve public POI performance and allow offline usage #1169 - Added …
Browse files Browse the repository at this point in the history
…ablity to create only the poi geojson file
  • Loading branch information
HarelM committed May 26, 2020
1 parent 8d09ca2 commit 66f955e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
6 changes: 4 additions & 2 deletions IsraelHiking.API/Controllers/UpdateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public async Task<IActionResult> PostUpdateData(UpdateRequest request)
request.UpdateOsmFile == false &&
request.DownloadOsmFile == false &&
request.Images == false &&
request.SiteMap == false)
request.SiteMap == false &&
request.OfflinePoisFile == false)
{
request = new UpdateRequest
{
Expand All @@ -78,7 +79,8 @@ public async Task<IActionResult> PostUpdateData(UpdateRequest request)
UpdateOsmFile = true,
DownloadOsmFile = true,
SiteMap = true,
Images = true
Images = true,
OfflinePoisFile = true
};
_logger.LogInformation("No specific filters were applied, updating all databases.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public interface IPointsOfInterestFilesCreatorExecutor
/// This function creates the sitemap.xml file inside the wwwroot folder
/// </summary>
/// <param name="features"></param>
void Create(List<Feature> features);
void CreateSiteMapXmlFile(List<Feature> features);

/// <summary>
/// This function creates the pois-slim.geojson file inside the wwwroot folder
/// </summary>
/// <param name="features"></param>
void CreateOfflinePoisFile(List<Feature> features);
}
}
13 changes: 3 additions & 10 deletions IsraelHiking.API/Executors/PointsOfInterestFilesCreatorExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,7 @@ public PointsOfInterestFilesCreatorExecutor(IFileSystemHelper fileSystemHelper,
}

/// <inheritdoc/>
public void Create(List<Feature> features)
{
_logger.LogInformation($"Starting points of interest files creation: {features.Count}.");
CreateSitemapXmlFile(features);
CreateOfflinePoisFile(features);
_logger.LogInformation($"Finished points of interest files creation: {features.Count}.");
}

private void CreateSitemapXmlFile(List<Feature> features)
public void CreateSiteMapXmlFile(List<Feature> features)
{
using (var fileStream = _fileSystemHelper.CreateWriteStream(Path.Combine(_environment.WebRootPath, "sitemap.xml")))
{
Expand All @@ -83,7 +75,8 @@ private void CreateSitemapXmlFile(List<Feature> features)
}
}

private void CreateOfflinePoisFile(List<Feature> features)
/// <inheritdoc/>
public void CreateOfflinePoisFile(List<Feature> features)
{
var collection = new FeatureCollection();
var slimCollection = new FeatureCollection();
Expand Down
14 changes: 13 additions & 1 deletion IsraelHiking.API/Services/Osm/DatabasesUpdaterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ public async Task Rebuild(UpdateRequest request)
{
await RebuildSiteMap();
}
if (request.OfflinePoisFile)
{
await RebuildOfflinePoisFile();
}
}

private async Task RebuildPointsOfInterest()
Expand Down Expand Up @@ -221,8 +225,16 @@ private async Task RebuildSiteMap()
{
_logger.LogInformation("Starting rebuilding sitemap.");
var features = await _elasticSearchGateway.GetAllPointsOfInterest();
_pointsOfInterestFilesCreatorExecutor.Create(features);
_pointsOfInterestFilesCreatorExecutor.CreateSiteMapXmlFile(features);
_logger.LogInformation("Finished rebuilding sitemap.");
}

private async Task RebuildOfflinePoisFile()
{
_logger.LogInformation("Starting rebuilding offline pois file.");
var features = await _elasticSearchGateway.GetAllPointsOfInterest();
_pointsOfInterestFilesCreatorExecutor.CreateOfflinePoisFile(features);
_logger.LogInformation("Finished rebuilding offline pois file.");
}
}
}
6 changes: 5 additions & 1 deletion IsraelHiking.Common/UpdateRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public class UpdateRequest
/// Update site map xml file and offline points of interest file
/// </summary>
public bool SiteMap { get; set; }

/// <summary>
/// Update pois file
/// </summary>
public bool OfflinePoisFile { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void TestRebuild_ShouldRebuildHighwaysAndPoints()

_elasticSearchGateway.Received(1).UpdateHighwaysZeroDownTime(Arg.Any<List<Feature>>());
_elasticSearchGateway.Received(1).UpdatePointsOfInterestZeroDownTime(Arg.Any<List<Feature>>());
_pointsOfInterestFilesCreatorExecutor.Received(1).Create(Arg.Any<List<Feature>>());
_pointsOfInterestFilesCreatorExecutor.Received(1).CreateSiteMapXmlFile(Arg.Any<List<Feature>>());
}

[TestMethod]
Expand Down

0 comments on commit 66f955e

Please sign in to comment.