Skip to content

Commit

Permalink
source 使用 Layer 名称为 key,修复缓存 SQL 导致的查询错误
Browse files Browse the repository at this point in the history
  • Loading branch information
zlzforever committed May 11, 2024
1 parent 52886a6 commit 2e43fe8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 27 deletions.
57 changes: 30 additions & 27 deletions src/ZMap.Source.Postgre/PostgreSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,46 +48,49 @@ public override async Task<IEnumerable<Feature>> GetFeaturesInExtentAsync(Envelo
// sql =
// $"SELECT CASE WHEN ST_HasArc({Geometry}) THEN {Geometry} ELSE ST_Simplify(ST_Force2D({Geometry}), 0.00001, true) END as geom{columnSql} from (SELECT {Geometry} as geom{columnSql} FROM {Table} WHERE {@where} {Geometry} && ST_MakeEnvelope({bbox.MinX}, {bbox.MinY},{bbox.MaxX},{bbox.MaxY}, {SRID})) t";

var sqlBuilder = new StringBuilder();
if (Properties == null || Properties.Count == 0)
var baseSql = BaseSql.GetOrAdd(Key, (_) =>
{
sqlBuilder.Append("SELECT * ").Append("FROM ").Append(Table).Append(" WHERE ");
}
else
{
sqlBuilder.Append("SELECT");
var containsId = false;
foreach (var property in Properties)
var sqlBuilder = new StringBuilder();
if (Properties == null || Properties.Count == 0)
{
sqlBuilder.Append("SELECT * ").Append("FROM ").Append(Table).Append(" WHERE ");
}
else
{
if (property == Geometry)
sqlBuilder.Append("SELECT");
var containsId = false;
foreach (var property in Properties)
{
continue;
if (property == Geometry)
{
continue;
}
if (containsId == false && property == Id)
{
containsId = true;
}
sqlBuilder.Append(' ').Append(property).Append(',');
}
if (containsId == false && property == Id)
if (!containsId)
{
containsId = true;
sqlBuilder.Append(' ').Append(Id).Append(',');
}
sqlBuilder.Append(' ').Append(property).Append(',');
sqlBuilder.Append(' ').Append(Geometry).Append(" WHERE ");
}
if (!containsId)
sqlBuilder.Append(Geometry).Append(" && ST_MakeEnvelope(@MinX, @MinY, @MaxX, @MaxY, @Srid)");
if (!string.IsNullOrEmpty(Where))
{
sqlBuilder.Append(' ').Append(Id).Append(',');
sqlBuilder.Append(" AND ").Append(Where);
}
sqlBuilder.Append(' ').Append(Geometry).Append(" WHERE ");
}

sqlBuilder.Append(Geometry).Append(" && ST_MakeEnvelope(@MinX, @MinY, @MaxX, @MaxY, @Srid)");

if (!string.IsNullOrEmpty(Where))
{
sqlBuilder.Append(" AND ").Append(Where);
}

var baseSql = sqlBuilder.ToString();
return sqlBuilder.ToString();
});

string sql;
if (!string.IsNullOrEmpty(Filter))
Expand Down
2 changes: 2 additions & 0 deletions src/ZMap/Source/ISource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace ZMap.Source;
/// </summary>
public interface ISource : IDisposable
{
string Key { get; set; }

/// <summary>
/// 数据源名称
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/ZMap/Source/RasterSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace ZMap.Source;

public abstract class RasterSource : IRasterSource
{
public string Key { get; set; }
public string Name { get; set; }

/// <summary>
Expand All @@ -16,6 +17,7 @@ public abstract class RasterSource : IRasterSource
/// <param name="extent"></param>
/// <returns></returns>
public abstract Task<byte[]> GetImageInExtentAsync(Envelope extent);

public abstract Envelope GetEnvelope();
public abstract ISource Clone();
public abstract void Dispose();
Expand Down
2 changes: 2 additions & 0 deletions src/ZMap/Source/VectorSourceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ namespace ZMap.Source;

public abstract class VectorSourceBase : IVectorSource
{
public string Key { get; set; }

/// <summary>
/// 数据源名称
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/ZServer/Store/LayerStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ private async Task<ISource> RestoreSourceAsync(string resourceGroup, string name
return null;
}

source.Key = name;
var properties = PropertyCache.GetOrAdd(source.GetType(), t =>
{
return t.GetProperties().Where(z => z.CanWrite)
Expand Down

0 comments on commit 2e43fe8

Please sign in to comment.