microsoft / microsoft/sqlmanagementobjects
JobServer constructor shouldn't run a SQL query
オープン
まだ誰も着手していません。
enhancement
- 主要言語
- C#
- スター
- 143
- フォーク
- 28
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
the JobServer class requires initializing its parent's Databases collection to construct itself:
internal JobServer(Server parentsrv, ObjectKeyBase key, SqlSmoState state) :
base(key, state)
{
// even though we called with the parent collection of the column, we will
// place the JobServer under the right collection
singletonParent = parentsrv as Server;
// WATCH OUT! we are setting the m_server value here, because JobServer does
// not live in a collection, but directly under the Database
SetServerObject( parentsrv.GetServerObject());
m_comparer = parentsrv.Databases["msdb"].StringComparer;
jobCategories = null;
alertCategories = null;
operatorCategories = null;
alertSystem = null;
alerts = null;
operators = null;
targetServers = null;
targetServerGroups = null;
jobs = null;
sharedSchedules = null;
}
- It shouldn't be making a SQL query of any kind in the constructor anyway
- Populating the databases collection is hugely expensive
- SqlSmoObject has a way to delay load StringComparer already that doesn't populate the collection, this object may just need a little refactoring of that method to support specifying msdb as the database to use for the query.
I found this by accident while trying to write a test for something else.
This code blows up because Databases["msdb"] doesn't exist:
var smoFilter = "[contains(@Name, 'SmoBaseline')]";
db.Parent.Databases.ClearAndInitialize($"[@Name='{Urn.EscapeString(db.Name)}']", Enumerable.Empty<string>());
db.Parent.Logins.ClearAndInitialize(smoFilter, Enumerable.Empty<string>());
db.Parent.LinkedServers.ClearAndInitialize(smoFilter, Enumerable.Empty<string>());
if (db.Parent.IsSupportedObject<JobServer>())
{
db.Parent.JobServer.Jobs.ClearAndInitialize(smoFilter, Enumerable.Empty<string>());
}
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
issue に示されている JobServer コンストラクターから始め、parentsrv.Databases["msdb"] が StringComparer をどのように取得するかを調べます。これを SqlSmoObject に既に存在する StringComparer の遅延読み込みと比較し、提供されている ClearAndInitialize テストシナリオを使って、JobServer を構築しても Databases が設定されず、msdb が存在しない場合にも失敗しないことを検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- csharp, sql
- 領域
- databases
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100