Skip to content

Commit

Permalink
Scrolling to maintenance index, improvements in sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Syrovatchenko committed Jun 29, 2020
1 parent 4401b9d commit e30f8cd
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 67 deletions.
17 changes: 2 additions & 15 deletions Forms/MainBox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 45 additions & 36 deletions Forms/MainBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,12 @@ private void ScanIndexesFinish(object sender, RunWorkerCompletedEventArgs e) {
List<Index> indexes = _indexes.Where(_ => _.Fragmentation >= (Settings.Options.SkipOperation == IndexOp.IGNORE ? Settings.Options.FirstThreshold : 0)
&& _.PagesCount >= Settings.Options.MinIndexSize.PageSize()
&& _.PagesCount <= Settings.Options.MaxIndexSize.PageSize())
.OrderBy(_ => _.Fragmentation < Settings.Options.FirstThreshold ? 3 : (_.Fragmentation < Settings.Options.SecondThreshold ? 2 : 1 ))
.OrderBy(_ => _.Fragmentation < Settings.Options.FirstThreshold
&& Settings.Options.SkipOperation != Settings.Options.FirstOperation
? 3
: _.Fragmentation < Settings.Options.SecondThreshold
&& Settings.Options.FirstOperation != Settings.Options.SecondOperation
? 2 : 1 )
.ThenByDescending(_ => (_.Fragmentation + 0.1) * _.PagesCount).ToList();

QueryEngine.UpdateFixType(indexes);
Expand Down Expand Up @@ -312,11 +317,16 @@ private void buttonFix_ItemClick(object sender, ItemClickEventArgs e) {

buttonStopFix.Visibility = BarItemVisibility.Always;

List<Index> selIndex = ((List<Index>)view.DataSource).Where(_ => _.IsSelected).ToList();
List<Index> selIndex = ((List<Index>)view.DataSource).Where(_ => _.IsSelected && _.FixType != IndexOp.SKIP).ToList();

List<Index> fixIndex =
selIndex.Where(x => Settings.ActiveHost.Databases.Any(y => y == x.DatabaseName) && x.FixType != IndexOp.SKIP)
.OrderBy(_ => _.Fragmentation < Settings.Options.FirstThreshold ? 3 : (_.Fragmentation < Settings.Options.SecondThreshold ? 2 : 1 ))
selIndex.Where(x => Settings.ActiveHost.Databases.Any(y => y == x.DatabaseName))
.OrderBy(_ => _.Fragmentation < Settings.Options.FirstThreshold
&& Settings.Options.SkipOperation != Settings.Options.FirstOperation
? 3
: _.Fragmentation < Settings.Options.SecondThreshold
&& Settings.Options.FirstOperation != Settings.Options.SecondOperation
? 2 : 1 )
.ThenByDescending(_ => (_.Fragmentation + 0.1) * _.PagesCount).ToList();

_ps = new ProgressStatus
Expand Down Expand Up @@ -362,9 +372,20 @@ private void buttonFix_ItemClick(object sender, ItemClickEventArgs e) {
}

private void FixIndexesProgressChanged(object sender, ProgressChangedEventArgs e) {
taskbar.ProgressCurrentValue = e.ProgressPercentage;
view.RefreshData();
taskbar.ProgressCurrentValue = e.ProgressPercentage + 1;
UpdateProgressStats();

if (e.UserState != null) {
Index index = (Index)e.UserState;
var rowHandle = view.FindRow(index);
if (rowHandle != GridControl.InvalidRowHandle) {
view.RefreshRow(rowHandle);
view.SelectRow(rowHandle);
view.MakeRowVisible(rowHandle);
}
}

view.RefreshData();
}

private BackgroundWorker _workerFix;
Expand All @@ -376,50 +397,48 @@ private void FixIndexes(object sender, DoWorkEventArgs e) {
using (var connectionList = new ConnectionList(Settings.ActiveHost)) {

for (int i = 0; i < indexes.Count; i++) {
Index item = indexes[i];
Index index = indexes[i];
if (_workerFix.CancellationPending) {
Output.Current.Add("Canceled");
e.Cancel = true;
return;
}

item.Progress = Resources.IconRun;
index.Progress = Resources.IconRun;
_ps.Indexes++;
_ps.IndexesSize += item.PagesCount;
_workerFix.ReportProgress(i + 1);
_ps.IndexesSize += index.PagesCount;
_workerFix.ReportProgress(i, index);

Output.Current.AddCaption(item.ToString());
Output.Current.AddCaption(index.ToString());
Stopwatch watch = Stopwatch.StartNew();

string sql = string.Empty;
SqlConnection connection = connectionList.Get(item.DatabaseName);
SqlConnection connection = connectionList.Get(index.DatabaseName);
if (connection != null) {
sql = QueryEngine.FixIndex(connection, item);
sql = QueryEngine.FixIndex(connection, index);
}

item.Progress = Resources.IconOk;

watch.Stop();
Output.Current.Add(index.ToString(), sql, index.Duration);

item.Duration = watch.ElapsedMilliseconds;
Output.Current.Add(item.ToString(), sql, item.Duration);
_workerFix.ReportProgress(i + 1);
index.Progress = Resources.IconOk;
index.Duration = watch.ElapsedMilliseconds;
_ps.SavedSpace += (index.PagesCountBefore ?? 0);

if (!string.IsNullOrEmpty(item.Error)) {
Output.Current.Add(item.ToString(), item.Error);
item.Progress = Resources.IconError;
if (!string.IsNullOrEmpty(index.Error)) {
Output.Current.Add(index.ToString(), index.Error);
index.Progress = Resources.IconError;
_ps.Errors++;
}
else {
if (Settings.Options.DelayAfterFix > 0 && i < indexes.Count - 1) {
item.Progress = Resources.IconDelay;
_workerFix.ReportProgress(i, index);
index.Progress = Resources.IconDelay;
Thread.Sleep(Settings.Options.DelayAfterFix);
item.Progress = Resources.IconOk;
index.Progress = Resources.IconOk;
}
}

_ps.SavedSpace += (item.PagesCountBefore ?? 0);
_workerFix.ReportProgress(i + 2);
_workerFix.ReportProgress(i, index);
}
}
}
Expand Down Expand Up @@ -893,16 +912,6 @@ private void ButtonAboutClick(object sender, ItemClickEventArgs e) {
}
}

private void ButtonFeedbackClick(object sender, ItemClickEventArgs e) {
try {
Process.Start(Resources.GitHubLink);
}
catch (Exception ex) {
Output.Current.Add($"Error: {ex.Source}", ex.Message);
XtraMessageBox.Show(ex.Message.Replace(". ", "." + Environment.NewLine), ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

#endregion

#region Save/Restore Sort
Expand Down
Binary file removed Images/icon_feedback.png
Binary file not shown.
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
[assembly: AssemblyCopyright("Sergii Syrovatchenko")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.0.64")]
[assembly: AssemblyFileVersion("1.0.0.64")]
[assembly: AssemblyVersion("1.0.0.65")]
[assembly: AssemblyFileVersion("1.0.0.65")]
10 changes: 0 additions & 10 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@
<data name="IsSparse" xml:space="preserve">
<value>IsSparse</value>
</data>
<data name="IconFeedback" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Images\icon_feedback.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="FixType" xml:space="preserve">
<value>FixType</value>
</data>
Expand Down
1 change: 0 additions & 1 deletion SQLIndexManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@
<None Include="Images\icon_delay.png" />
<Content Include="Images\icon_exclude.png" />
<Content Include="Images\icon.ico" />
<None Include="Images\icon_feedback.png" />
<None Include="Images\icon_fix.png" />
<None Include="Images\icon_filter.png" />
<Content Include="Images\icon_include.png" />
Expand Down

0 comments on commit e30f8cd

Please sign in to comment.