diff --git a/devdocs/todo.txt b/devdocs/todo.txt index 496b41b2..d2f68497 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -5,11 +5,14 @@ ## IMMEDIATE ITEMS + + //PICKLISTS: todo: move to client work then back here to document after todo: document picklist and tag search etc after client example working in widget form +todo: add query fail logging to datalist just like done with picklist so in production can catch mysterious problems more easily TODO: BizRoles.cs seems to get hammered on every single request, is it efficient? diff --git a/server/AyaNova/Controllers/PickListController.cs b/server/AyaNova/Controllers/PickListController.cs index a62ae7e0..269bef5b 100644 --- a/server/AyaNova/Controllers/PickListController.cs +++ b/server/AyaNova/Controllers/PickListController.cs @@ -80,7 +80,7 @@ namespace AyaNova.Api.Controllers //Instantiate the business object handler PickListBiz biz = PickListBiz.GetBiz(ct, HttpContext); - var o = await biz.GetPickListAsync(PickList, query, inactive); + var o = await biz.GetPickListAsync(PickList, query, inactive, log); if (o == null) return BadRequest(new ApiErrorResponse(biz.Errors)); else diff --git a/server/AyaNova/PickList/PickListFetcher.cs b/server/AyaNova/PickList/PickListFetcher.cs index 6d872cec..51ccf5e5 100644 --- a/server/AyaNova/PickList/PickListFetcher.cs +++ b/server/AyaNova/PickList/PickListFetcher.cs @@ -3,14 +3,15 @@ using Newtonsoft.Json.Linq; using AyaNova.Models; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; - +using Microsoft.Extensions.Logging; namespace AyaNova.PickList { internal static class PickListFetcher { - internal static async Task> GetResponseAsync(IAyaPickList PickList, string autoCompleteQuery, string tagSpecificQuery, bool includeInactive, AyContext ct) + internal static async Task> GetResponseAsync(IAyaPickList PickList, string autoCompleteQuery, + string tagSpecificQuery, bool includeInactive, AyContext ct, ILogger log) { //Sort out effective Template @@ -45,20 +46,32 @@ namespace AyaNova.PickList //GET DATA RETURN ROWS command.CommandText = q; - using (var dr = await command.ExecuteReaderAsync()) + try { - while (dr.Read()) + using (var dr = await command.ExecuteReaderAsync()) { - //query is always in the same order: - //plId, plActive, plName - ret.Add(new NameIdActiveItem + while (dr.Read()) { - Id = dr.GetInt64(0), - Active = dr.GetBoolean(1), - Name = dr.GetString(2) - }); + //query is always in the same order: + //plId, plActive, plName + ret.Add(new NameIdActiveItem + { + Id = dr.GetInt64(0), + Active = dr.GetBoolean(1), + Name = dr.GetString(2) + }); + } } } + catch (Npgsql.PostgresException e) + { + //log out the exception and the query + log.LogInformation("PickList query failed unexpectedly. Query was:"); + log.LogInformation(q); + log.LogInformation(e,"DB Exception"); + throw new System.Exception("PickListFetcher - Query failed see log"); + + } } return ret; } diff --git a/server/AyaNova/PickList/PickListSqlBuilder.cs b/server/AyaNova/PickList/PickListSqlBuilder.cs index 8c51f6dc..68ed8c9c 100644 --- a/server/AyaNova/PickList/PickListSqlBuilder.cs +++ b/server/AyaNova/PickList/PickListSqlBuilder.cs @@ -156,7 +156,7 @@ namespace AyaNova.PickList } - if (HasAutoCompleteQuery) + if (HasAutoCompleteQuery && !HasTagSpecificQuery) lWhere.Add(sWhere); diff --git a/server/AyaNova/biz/PickListBiz.cs b/server/AyaNova/biz/PickListBiz.cs index 712beb6b..c1b39732 100644 --- a/server/AyaNova/biz/PickListBiz.cs +++ b/server/AyaNova/biz/PickListBiz.cs @@ -1,6 +1,7 @@ using System.Linq; using System.Threading.Tasks; using System.Collections.Generic; +using Microsoft.Extensions.Logging; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json.Linq; using AyaNova.Util; @@ -69,7 +70,7 @@ namespace AyaNova.Biz //get picklist - internal async Task> GetPickListAsync(IAyaPickList PickList, string query, bool inactive) + internal async Task> GetPickListAsync(IAyaPickList PickList, string query, bool inactive, ILogger log) { //Crack and validate the query part set a broken rule if not valid and return null @@ -133,7 +134,7 @@ namespace AyaNova.Biz } //Autocomplete and tagonly query terms now set for consumption by PickListFetcher, ready to fetch... - List items = await PickListFetcher.GetResponseAsync(PickList, AutoCompleteQuery, TagSpecificQuery, inactive, ct); + List items = await PickListFetcher.GetResponseAsync(PickList, AutoCompleteQuery, TagSpecificQuery, inactive, ct, log); return items; }