Skip to content

Commit

Permalink
优化使用分表的埋点名,支持没有下划线的分表方式,只要末尾是数字即可
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Sep 9, 2024
1 parent 9d2bf5a commit 07ad12c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions XCode/DataAccessLayer/DAL_DbOperate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,16 @@ public static String[] GetTables(String sql, Boolean trimShard)
var tableName = item.Groups[1].Value;
if (trimShard)
{
var p = tableName.LastIndexOf('_');
if (p > 0 && tableName[(p + 1)..].ToInt() > 0)
// 从尾部开始找到第一个数字,然后再找到下划线
var p = -1;
for (var i = tableName.Length - 1; i >= 0; i--)
{
if (!Char.IsDigit(tableName[i])) break;
p = i;
}
if (p > 0 && tableName[p - 1] == '_') p--;
// 数字长度至少是2,否则不是分表
if (p > 0 && p + 2 <= tableName.Length)
{
tableName = tableName[..p];
}
Expand Down

0 comments on commit 07ad12c

Please sign in to comment.