Much faster for grid refresh
This commit is contained in:
parent
a3542c53e2
commit
1fcacb9cfb
@ -119,6 +119,9 @@ namespace ApplicationServices
|
|||||||
|
|
||||||
var udi = book.UserDefinedItem;
|
var udi = book.UserDefinedItem;
|
||||||
|
|
||||||
|
if (udi.Tags == newTags)
|
||||||
|
return 0;
|
||||||
|
|
||||||
// Attach() NoTracking entities before SaveChanges()
|
// Attach() NoTracking entities before SaveChanges()
|
||||||
udi.Tags = newTags;
|
udi.Tags = newTags;
|
||||||
context.Attach(udi).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
context.Attach(udi).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||||
@ -144,6 +147,9 @@ namespace ApplicationServices
|
|||||||
|
|
||||||
var udi = libraryBook.Book.UserDefinedItem;
|
var udi = libraryBook.Book.UserDefinedItem;
|
||||||
|
|
||||||
|
if (udi.BookStatus == liberatedStatus && udi.BookLocation == finalAudioPath)
|
||||||
|
return 0;
|
||||||
|
|
||||||
// Attach() NoTracking entities before SaveChanges()
|
// Attach() NoTracking entities before SaveChanges()
|
||||||
udi.BookStatus = liberatedStatus;
|
udi.BookStatus = liberatedStatus;
|
||||||
udi.BookLocation = finalAudioPath;
|
udi.BookLocation = finalAudioPath;
|
||||||
@ -169,6 +175,9 @@ namespace ApplicationServices
|
|||||||
|
|
||||||
var udi = libraryBook.Book.UserDefinedItem;
|
var udi = libraryBook.Book.UserDefinedItem;
|
||||||
|
|
||||||
|
if (udi.PdfStatus == liberatedStatus)
|
||||||
|
return 0;
|
||||||
|
|
||||||
// Attach() NoTracking entities before SaveChanges()
|
// Attach() NoTracking entities before SaveChanges()
|
||||||
udi.PdfStatus = liberatedStatus;
|
udi.PdfStatus = liberatedStatus;
|
||||||
context.Attach(udi).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
context.Attach(udi).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||||
|
|||||||
@ -7,10 +7,10 @@ namespace ApplicationServices
|
|||||||
{
|
{
|
||||||
public static class SearchEngineCommands
|
public static class SearchEngineCommands
|
||||||
{
|
{
|
||||||
public static void FullReIndex()
|
public static void FullReIndex(SearchEngine engine = null)
|
||||||
{
|
{
|
||||||
var engine = new SearchEngine(DbContexts.GetContext());
|
engine ??= new SearchEngine();
|
||||||
engine.CreateNewIndex();
|
engine.CreateNewIndex(DbContexts.GetContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SearchResultSet Search(string searchString) => performSearchEngineFunc_safe(e =>
|
public static SearchResultSet Search(string searchString) => performSearchEngineFunc_safe(e =>
|
||||||
@ -27,28 +27,28 @@ namespace ApplicationServices
|
|||||||
|
|
||||||
private static void performSearchEngineAction_safe(Action<SearchEngine> action)
|
private static void performSearchEngineAction_safe(Action<SearchEngine> action)
|
||||||
{
|
{
|
||||||
var engine = new SearchEngine(DbContexts.GetContext());
|
var engine = new SearchEngine();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
action(engine);
|
action(engine);
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException)
|
catch (FileNotFoundException)
|
||||||
{
|
{
|
||||||
FullReIndex();
|
FullReIndex(engine);
|
||||||
action(engine);
|
action(engine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static T performSearchEngineFunc_safe<T>(Func<SearchEngine, T> action)
|
private static T performSearchEngineFunc_safe<T>(Func<SearchEngine, T> action)
|
||||||
{
|
{
|
||||||
var engine = new SearchEngine(DbContexts.GetContext());
|
var engine = new SearchEngine();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return action(engine);
|
return action(engine);
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException)
|
catch (FileNotFoundException)
|
||||||
{
|
{
|
||||||
FullReIndex();
|
FullReIndex(engine);
|
||||||
return action(engine);
|
return action(engine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace DataLayer
|
namespace DataLayer
|
||||||
{
|
{
|
||||||
|
// only library importing should use tracking. All else should be NoTracking.
|
||||||
|
// only library importing should directly query Book. All else should use LibraryBook
|
||||||
public static class BookQueries
|
public static class BookQueries
|
||||||
{
|
{
|
||||||
public static Book GetBook_Flat_NoTracking(this LibationContext context, string productId)
|
public static Book GetBook_Flat_NoTracking(this LibationContext context, string productId)
|
||||||
|
|||||||
@ -4,6 +4,8 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace DataLayer
|
namespace DataLayer
|
||||||
{
|
{
|
||||||
|
// only library importing should use tracking. All else should be NoTracking.
|
||||||
|
// only library importing should directly query Book. All else should use LibraryBook
|
||||||
public static class LibraryQueries
|
public static class LibraryQueries
|
||||||
{
|
{
|
||||||
//// tracking is a bad idea for main grid. it prevents anything else from updating entities unless getting them from the grid
|
//// tracking is a bad idea for main grid. it prevents anything else from updating entities unless getting them from the grid
|
||||||
|
|||||||
@ -361,7 +361,7 @@ namespace LibationLauncher
|
|||||||
config.ConfigureLogging();
|
config.ConfigureLogging();
|
||||||
|
|
||||||
// Fwd Console to serilog.
|
// Fwd Console to serilog.
|
||||||
// Serilog also write to Console (should probably change this) so it might be asking for trouble.
|
// Serilog also writes to Console (should probably change this) so it might be asking for trouble.
|
||||||
// SerilogTextWriter needs to be more robust and tested. Esp the Write() methods.
|
// SerilogTextWriter needs to be more robust and tested. Esp the Write() methods.
|
||||||
// Empirical testing so far has shown no issues.
|
// Empirical testing so far has shown no issues.
|
||||||
Console.SetOut(new MultiTextWriter(origOut, new SerilogTextWriter()));
|
Console.SetOut(new MultiTextWriter(origOut, new SerilogTextWriter()));
|
||||||
|
|||||||
@ -18,8 +18,6 @@ namespace LibationSearchEngine
|
|||||||
{
|
{
|
||||||
public const Lucene.Net.Util.Version Version = Lucene.Net.Util.Version.LUCENE_30;
|
public const Lucene.Net.Util.Version Version = Lucene.Net.Util.Version.LUCENE_30;
|
||||||
|
|
||||||
private LibationContext context { get; }
|
|
||||||
|
|
||||||
// not customizable. don't move to config
|
// not customizable. don't move to config
|
||||||
private static string SearchEngineDirectory { get; }
|
private static string SearchEngineDirectory { get; }
|
||||||
= new System.IO.DirectoryInfo(Configuration.Instance.LibationFiles).CreateSubdirectory("SearchEngine").FullName;
|
= new System.IO.DirectoryInfo(Configuration.Instance.LibationFiles).CreateSubdirectory("SearchEngine").FullName;
|
||||||
@ -32,8 +30,6 @@ namespace LibationSearchEngine
|
|||||||
// the workaround which allows displaying all books when query is empty
|
// the workaround which allows displaying all books when query is empty
|
||||||
public const string ALL_QUERY = "*:*";
|
public const string ALL_QUERY = "*:*";
|
||||||
|
|
||||||
public SearchEngine(LibationContext context) => this.context = context;
|
|
||||||
|
|
||||||
#region index rules
|
#region index rules
|
||||||
private static ReadOnlyDictionary<string, Func<LibraryBook, string>> idIndexRules { get; }
|
private static ReadOnlyDictionary<string, Func<LibraryBook, string>> idIndexRules { get; }
|
||||||
= new ReadOnlyDictionary<string, Func<LibraryBook, string>>(
|
= new ReadOnlyDictionary<string, Func<LibraryBook, string>>(
|
||||||
@ -202,7 +198,7 @@ namespace LibationSearchEngine
|
|||||||
/// create new. ie: full re-index
|
/// create new. ie: full re-index
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="overwrite"></param>
|
/// <param name="overwrite"></param>
|
||||||
public void CreateNewIndex(bool overwrite = true)
|
public void CreateNewIndex(LibationContext context, bool overwrite = true)
|
||||||
{
|
{
|
||||||
// 300 titles: 200- 400 ms
|
// 300 titles: 200- 400 ms
|
||||||
// 1021 titles: 1777-2250 ms
|
// 1021 titles: 1777-2250 ms
|
||||||
@ -235,7 +231,7 @@ namespace LibationSearchEngine
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Long running. Use await Task.Run(() => UpdateBook(productId))</summary>
|
/// <summary>Long running. Use await Task.Run(() => UpdateBook(productId))</summary>
|
||||||
public void UpdateBook(string productId)
|
public void UpdateBook(LibationContext context, string productId)
|
||||||
{
|
{
|
||||||
var libraryBook = context.GetLibraryBook_Flat_NoTracking(productId);
|
var libraryBook = context.GetLibraryBook_Flat_NoTracking(productId);
|
||||||
var term = new Term(_ID_, productId);
|
var term = new Term(_ID_, productId);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
namespace LibationWinForms.Dialogs
|
namespace LibationWinForms.Dialogs
|
||||||
{
|
{
|
||||||
partial class EditTagsDialog
|
partial class BookDetailsDialog
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
@ -3,15 +3,15 @@ using System.Windows.Forms;
|
|||||||
|
|
||||||
namespace LibationWinForms.Dialogs
|
namespace LibationWinForms.Dialogs
|
||||||
{
|
{
|
||||||
public partial class EditTagsDialog : Form
|
public partial class BookDetailsDialog : Form
|
||||||
{
|
{
|
||||||
public string NewTags { get; private set; }
|
public string NewTags { get; private set; }
|
||||||
|
|
||||||
public EditTagsDialog()
|
public BookDetailsDialog()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
public EditTagsDialog(string title, string rawTags) : this()
|
public BookDetailsDialog(string title, string rawTags) : this()
|
||||||
{
|
{
|
||||||
this.Text = $"Edit Tags - {title}";
|
this.Text = $"Edit Tags - {title}";
|
||||||
|
|
||||||
@ -255,11 +255,11 @@ namespace LibationWinForms
|
|||||||
// EditTagsDialog should display better-formatted title
|
// EditTagsDialog should display better-formatted title
|
||||||
liveGridEntry.TryDisplayValue(nameof(liveGridEntry.Title), out string value);
|
liveGridEntry.TryDisplayValue(nameof(liveGridEntry.Title), out string value);
|
||||||
|
|
||||||
var editTagsForm = new EditTagsDialog(value, liveGridEntry.Tags);
|
var bookDetailsForm = new BookDetailsDialog(value, liveGridEntry.Tags);
|
||||||
if (editTagsForm.ShowDialog() != DialogResult.OK)
|
if (bookDetailsForm.ShowDialog() != DialogResult.OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var qtyChanges = LibraryCommands.UpdateTags(liveGridEntry.GetBook(), editTagsForm.NewTags);
|
var qtyChanges = LibraryCommands.UpdateTags(liveGridEntry.GetBook(), bookDetailsForm.NewTags);
|
||||||
if (qtyChanges == 0)
|
if (qtyChanges == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user