Glimpse shows Duplicate EF queries
I'm having problems with my MVC 4 application running too slowly. I
installed Glimpse to profile the application. I think I've found part of
the problem: many of my EF queries appear to be running twice! Here's my
HomeController that is pulling some alerts:
[HttpGet]
public virtual ActionResult Index()
{
var reportStart = DateTime.Today;
var reportEnd = DateTime.Today.AddMonths(1);
var query = _tameUow.Alerts
.FindBy(a => a.ApprovalStatusId ==
(int)AlertApprovalStatusCodes.Approved &&
(a.ScheduledStartDateTime >=
reportStart &&
a.ScheduledStartDateTime <=
reportEnd), a => a.SubmittedBy, a =>
a.ApprovalManager, a =>
a.ApprovalStatus);
var model = ListAlertsViewModelBuilder.Build(query, null, false,
false, false, false);
model.RequiredViewData = new RequiredViewDataModel("Upcoming
Alerts", "These are the upcoming active alerts for the next
month.", "Home");
return View(model);
}
But when I view the SQL tab in glimpse, it shows the query twice! At first
I thought it was just a bug and the same query was being displayed twice,
but they have different execution times, so I think that the query is
actually being run twice! Also, the little yellow exclamation mark shows
up as a warning. I THINK this is warning me that it is a duplicate
query...
http://i.imgur.com/jizQwKz.png What's going on here? I see this on all
the pages I've tested, I chose this one as an example because it is the
simplest. I tried setting a breakpoint on the query, and it is only being
hit once.
Here's the VMBuilder:
public static class ListAlertsViewModelBuilder
{
public static ListAlertsViewModel Build
(IQueryable<Alert> query
, string curUserExtId
, bool showSubmittedDateTime
, bool showStatus
, bool showActions
, bool showOwners)
{
var model = new ListAlertsViewModel();
var alerts = query.Select(a => new AlertDetailsViewModel() {
AlertId = (int)a.AlertId,
ApprovalManager = a.ApprovalManager,
ApprovalManagerExtId = a.ApprovalManagerExtId,
ApprovalStatus = a.ApprovalStatus,
ApprovalStatusId = (int)a.ApprovalStatusId,
Building = a.Building,
Cause = a.Cause,
//Comments = a.Comments,
Impact = a.Impact,
ScheduledEndDateTime = a.ScheduledEndDateTime,
ScheduledStartDateTime = a.ScheduledStartDateTime,
Service = a.Service,
SubmittedBy = a.SubmittedBy,
SubmittedByExtId = a.SubmittedByExtId,
SubmittedDateTime = a.SubmittedDateTime,
CurrentUserExtId = curUserExtId
});
model.ListAlerts = alerts;
model.ShowSubmittedDateTime = showSubmittedDateTime;
model.ShowStatus = showStatus;
model.ShowActions = showActions;
model.ShowOwners = showOwners;
return model;
}
}
And this is the FindBy method I'm using from my repository:
public IQueryable<T> FindBy(Expression<Func<T, bool>> predicate, params
Expression<Func<T, object>>[] includeProperties)
{
IQueryable<T> query = this.Context.Set<T>();
foreach (var include in includeProperties)
{
query.Include(include);
}
return query.Where(predicate);
}
Thursday, 12 September 2013
changing name html name attribute using javascript
changing name html name attribute using javascript
this is javascript code where I want to change the name attribute each
time new element is created. but when I try to access these elements from
servlet it shows me null value.What exctly I am doing wrong? any help
would be appreciated. Thanx in advance!!
function addRow()
{
var table = document.getElementById('table');
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "text";
element1.name ="item"+rowCount;
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
var element2 = document.createElement("input");
element2.type = "text";
element2.name ="amount"+rowCount;
cell2.appendChild(element2);
var cell3 = row.insertCell(2);
cell3.innerHTML = ' <input type="button" value="Edit"
onclick="editRow(this)"/> <input type="button" value="Delete"
onclick="deleteRow(this)"/>';
cell3.setAttribute("style", "display:none;");
var cell4 = row.insertCell(3);
cell4.innerHTML = '<input type="button" value="Save"
onClick="saveRow(this)">';
document.listform.hfield.value=rowCount;
}
this is javascript code where I want to change the name attribute each
time new element is created. but when I try to access these elements from
servlet it shows me null value.What exctly I am doing wrong? any help
would be appreciated. Thanx in advance!!
function addRow()
{
var table = document.getElementById('table');
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "text";
element1.name ="item"+rowCount;
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
var element2 = document.createElement("input");
element2.type = "text";
element2.name ="amount"+rowCount;
cell2.appendChild(element2);
var cell3 = row.insertCell(2);
cell3.innerHTML = ' <input type="button" value="Edit"
onclick="editRow(this)"/> <input type="button" value="Delete"
onclick="deleteRow(this)"/>';
cell3.setAttribute("style", "display:none;");
var cell4 = row.insertCell(3);
cell4.innerHTML = '<input type="button" value="Save"
onClick="saveRow(this)">';
document.listform.hfield.value=rowCount;
}
Trouble setting ubuntu vhost file
Trouble setting ubuntu vhost file
Ok. I'm trying to set my config files in ubuntu.
When I look in the sites-available folder, I see
000-default.conf ssl-default.conf
I have a site testsite.com that I need to configure the vhost for https
1) Can I just add a new vhost section to ssl-default.conf? Should I copy
the entire file to testsite.conf and make my edits there? 2) Where should
I put the set up for port 80? 000-default.conf? if I copy the file, do I
need to add the 000 to the file name so that it is read first? 3) where
can I put the info that used to be in the default file ie( allow
overrides, etc)
Thank you
Ok. I'm trying to set my config files in ubuntu.
When I look in the sites-available folder, I see
000-default.conf ssl-default.conf
I have a site testsite.com that I need to configure the vhost for https
1) Can I just add a new vhost section to ssl-default.conf? Should I copy
the entire file to testsite.conf and make my edits there? 2) Where should
I put the set up for port 80? 000-default.conf? if I copy the file, do I
need to add the 000 to the file name so that it is read first? 3) where
can I put the info that used to be in the default file ie( allow
overrides, etc)
Thank you
Wednesday, 11 September 2013
MySQL: How to optimize this query?
MySQL: How to optimize this query?
I almost spent a day to optimize this query:
SELECT
prod. *,
cat.slug category_slug,
sup.bname bname,
sup.slug bname_slug
FROM bb_admin.bb_directory_products AS prod
LEFT JOIN bb_admin.bb_categories_products AS cat
ON prod.primary_category_id = cat.category_id
LEFT JOIN bb_admin.bb_directory_suppliers AS sup
ON prod.supplier_id = sup.supplier_id
LEFT JOIN bb_admin.bb_directory_suppliers AS credit_sup
ON prod.credit_supplier_id = credit_sup.supplier_id
LEFT JOIN bb_admin.bb_directory_suppliers AS photo_sup
ON prod.photo_supplier_id = photo_sup.supplier_id
WHERE (
prod.status = '1'
OR prod.status = '3'
OR prod.status = '5'
)
AND (
sup.active_package_id != '1'
OR sup.active_package_id != '5'
OR sup.active_package_id != '6'
OR prod.supplier_id = '0'
)
AND (
sup.supplier_id = '1989'
OR credit_sup.supplier_id = '1989'
OR photo_sup.supplier_id = '1989'
)
GROUP BY prod.product_id
ORDER BY prod.priority_index ASC
Can you help me to optimized this query?
I almost spent a day to optimize this query:
SELECT
prod. *,
cat.slug category_slug,
sup.bname bname,
sup.slug bname_slug
FROM bb_admin.bb_directory_products AS prod
LEFT JOIN bb_admin.bb_categories_products AS cat
ON prod.primary_category_id = cat.category_id
LEFT JOIN bb_admin.bb_directory_suppliers AS sup
ON prod.supplier_id = sup.supplier_id
LEFT JOIN bb_admin.bb_directory_suppliers AS credit_sup
ON prod.credit_supplier_id = credit_sup.supplier_id
LEFT JOIN bb_admin.bb_directory_suppliers AS photo_sup
ON prod.photo_supplier_id = photo_sup.supplier_id
WHERE (
prod.status = '1'
OR prod.status = '3'
OR prod.status = '5'
)
AND (
sup.active_package_id != '1'
OR sup.active_package_id != '5'
OR sup.active_package_id != '6'
OR prod.supplier_id = '0'
)
AND (
sup.supplier_id = '1989'
OR credit_sup.supplier_id = '1989'
OR photo_sup.supplier_id = '1989'
)
GROUP BY prod.product_id
ORDER BY prod.priority_index ASC
Can you help me to optimized this query?
correct javascript syntax for two or more strings in operator
correct javascript syntax for two or more strings in operator
I wrote this piece of code, but I am not getting my syntax correct. I
tried it several ways. The first one below seems like it should work, but
I am not quite there yet. Please point me in the correct direction for
what the correct syntax is when comparing multiple strings
$(document).ready(function() {
var url = window.location.pathname.substring(1);
if ( [ 'page_id=11', 'page_id=19'].indexOf( url ) > -1 ) {
$('#main').css("background-color","#ebecee");
}
});
and I also tried like this
$(document).ready(function() {
var url = window.location.pathname.substring(1);
if(url.href.indexOf("page_id=11") > -1 && ("page_id=19") > -1 ) {
$('#main').css("background-color","#ebecee");
}
});
What is the correct way to write it?
I wrote this piece of code, but I am not getting my syntax correct. I
tried it several ways. The first one below seems like it should work, but
I am not quite there yet. Please point me in the correct direction for
what the correct syntax is when comparing multiple strings
$(document).ready(function() {
var url = window.location.pathname.substring(1);
if ( [ 'page_id=11', 'page_id=19'].indexOf( url ) > -1 ) {
$('#main').css("background-color","#ebecee");
}
});
and I also tried like this
$(document).ready(function() {
var url = window.location.pathname.substring(1);
if(url.href.indexOf("page_id=11") > -1 && ("page_id=19") > -1 ) {
$('#main').css("background-color","#ebecee");
}
});
What is the correct way to write it?
PayPal Java NVP API GetExpressCheckoutDetails - Missing Data
PayPal Java NVP API GetExpressCheckoutDetails - Missing Data
I'm calling the PayPal sandbox with a 'express checkout' process from a
java web application. The first call ('SetExpressCheckout') succeeds and I
receive a Token as expected.
The second call ('GetExpressCheckoutDetails') succeeds as well in regard
to getting an ACK=Success answer. But there is all the payer information
data like FIRSTNAME, LASTNAME or SHIPTOCITY missing.
Here's the URL I'm calling with parameters:
https://api-3t.sandbox.paypal.com:443/nvp?TOKEN=__MY_TOKEN__&VERSION=106.0&SIGNATURE=__MY_SIGNATURE__&METHOD=GetExpressCheckoutDetails&PWD=__MY_PASSWORD__&USER=__MY_USERNAME__
Here's the response's body I get:
TOKEN=__MY_TOKEN__&CHECKOUTSTATUS=PaymentActionNotInitiated&TIMESTAMP=2013%2d09%2d11T20%3a56%3a36Z&CORRELATIONID=bb3916c14aa78&ACK=Success&VERSION=106%2e0&BUILD=7645184&CURRENCYCODE=USD&AMT=12%2e00&SHIPPINGAMT=0%2e00&HANDLINGAMT=0%2e00&TAXAMT=0%2e00&INSURANCEAMT=0%2e00&SHIPDISCAMT=0%2e00&PAYMENTREQUEST_0_CURRENCYCODE=USD&PAYMENTREQUEST_0_AMT=12%2e00&PAYMENTREQUEST_0_SHIPPINGAMT=0%2e00&PAYMENTREQUEST_0_HANDLINGAMT=0%2e00&PAYMENTREQUEST_0_TAXAMT=0%2e00&PAYMENTREQUEST_0_INSURANCEAMT=0%2e00&PAYMENTREQUEST_0_SHIPDISCAMT=0%2e00&PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED=false&PAYMENTREQUEST_0_ADDRESSNORMALIZATIONSTATUS=None&PAYMENTREQUESTINFO_0_ERRORCODE=0
If I put the same request URL into Firefox I receive the response I would
expect:
TOKEN=__MY_TOKEN__&CHECKOUTSTATUS=PaymentActionNotInitiated&TIMESTAMP=2013%2d09%2d11T20%3a37%3a31Z&CORRELATIONID=7804316ba643d&ACK=Success&VERSION=106%2e0&BUILD=7645184&EMAIL=mne%2dcustomer2%40m%2dn%2de%2ede&PAYERID=QRZ57KR8PHVF4&PAYERSTATUS=verified&FIRSTNAME=Frank&LASTNAME=Forest&COUNTRYCODE=US&SHIPTONAME=Frank%20Forest&SHIPTOSTREET=1%20Main%20St&SHIPTOCITY=San%20Jose&SHIPTOSTATE=CA&SHIPTOZIP=95131&SHIPTOCOUNTRYCODE=US&SHIPTOCOUNTRYNAME=United%20States&ADDRESSSTATUS=Confirmed&CURRENCYCODE=USD&AMT=15%2e00&SHIPPINGAMT=0%2e00&HANDLINGAMT=0%2e00&TAXAMT=0%2e00&INSURANCEAMT=0%2e00&SHIPDISCAMT=0%2e00&PAYMENTREQUEST_0_CURRENCYCODE=USD&PAYMENTREQUEST_0_AMT=15%2e00&PAYMENTREQUEST_0_SHIPPINGAMT=0%2e00&PAYMENTREQUEST_0_HANDLINGAMT=0%2e00&PAYMENTREQUEST_0_TAXAMT=0%2e00&PAYMENTREQUEST_0_INSURANCEAMT=0%2e00&PAYMENTREQUEST_0_SHIPDISCAMT=0%2e00&PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED=false&PAYMENTREQUEST_0_SHIPTONAME=Frank%20Forest&PAYMENTREQUEST_0_SHIPTOSTREET=1%20Main%20St&PAYMENTREQUEST_
0_SHIPTOCITY=San%20Jose&PAYMENTREQUEST_0_SHIPTOSTATE=CA&PAYMENTREQUEST_0_SHIPTOZIP=95131&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=US&PAYMENTREQUEST_0_SHIPTOCOUNTRYNAME=United%20States&PAYMENTREQUEST_0_ADDRESSSTATUS=Confirmed&PAYMENTREQUEST_0_ADDRESSNORMALIZATIONSTATUS=None&PAYMENTREQUESTINFO_0_ERRORCODE=0
This expected answer contains PAYERID, FIRSTNAME, LASTNAME, SHIPTOSTREET,
SHIPTOCITY etc.
I tried calling the PayPal sandbox from java using
Apache HttpClient GET request
Apache HttpClient POST request
javax.net.ssl.HttpsURLConnection
java.net.URLConnection
I tried running the webapp in JBoss 7.1.1 on mac OS X and JBoss 7.2.0 on
win8.
The result is always the same. The payer information (name, address) is
missing when I call it from java.
Has anyone got an idea what is wrong?
I'm calling the PayPal sandbox with a 'express checkout' process from a
java web application. The first call ('SetExpressCheckout') succeeds and I
receive a Token as expected.
The second call ('GetExpressCheckoutDetails') succeeds as well in regard
to getting an ACK=Success answer. But there is all the payer information
data like FIRSTNAME, LASTNAME or SHIPTOCITY missing.
Here's the URL I'm calling with parameters:
https://api-3t.sandbox.paypal.com:443/nvp?TOKEN=__MY_TOKEN__&VERSION=106.0&SIGNATURE=__MY_SIGNATURE__&METHOD=GetExpressCheckoutDetails&PWD=__MY_PASSWORD__&USER=__MY_USERNAME__
Here's the response's body I get:
TOKEN=__MY_TOKEN__&CHECKOUTSTATUS=PaymentActionNotInitiated&TIMESTAMP=2013%2d09%2d11T20%3a56%3a36Z&CORRELATIONID=bb3916c14aa78&ACK=Success&VERSION=106%2e0&BUILD=7645184&CURRENCYCODE=USD&AMT=12%2e00&SHIPPINGAMT=0%2e00&HANDLINGAMT=0%2e00&TAXAMT=0%2e00&INSURANCEAMT=0%2e00&SHIPDISCAMT=0%2e00&PAYMENTREQUEST_0_CURRENCYCODE=USD&PAYMENTREQUEST_0_AMT=12%2e00&PAYMENTREQUEST_0_SHIPPINGAMT=0%2e00&PAYMENTREQUEST_0_HANDLINGAMT=0%2e00&PAYMENTREQUEST_0_TAXAMT=0%2e00&PAYMENTREQUEST_0_INSURANCEAMT=0%2e00&PAYMENTREQUEST_0_SHIPDISCAMT=0%2e00&PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED=false&PAYMENTREQUEST_0_ADDRESSNORMALIZATIONSTATUS=None&PAYMENTREQUESTINFO_0_ERRORCODE=0
If I put the same request URL into Firefox I receive the response I would
expect:
TOKEN=__MY_TOKEN__&CHECKOUTSTATUS=PaymentActionNotInitiated&TIMESTAMP=2013%2d09%2d11T20%3a37%3a31Z&CORRELATIONID=7804316ba643d&ACK=Success&VERSION=106%2e0&BUILD=7645184&EMAIL=mne%2dcustomer2%40m%2dn%2de%2ede&PAYERID=QRZ57KR8PHVF4&PAYERSTATUS=verified&FIRSTNAME=Frank&LASTNAME=Forest&COUNTRYCODE=US&SHIPTONAME=Frank%20Forest&SHIPTOSTREET=1%20Main%20St&SHIPTOCITY=San%20Jose&SHIPTOSTATE=CA&SHIPTOZIP=95131&SHIPTOCOUNTRYCODE=US&SHIPTOCOUNTRYNAME=United%20States&ADDRESSSTATUS=Confirmed&CURRENCYCODE=USD&AMT=15%2e00&SHIPPINGAMT=0%2e00&HANDLINGAMT=0%2e00&TAXAMT=0%2e00&INSURANCEAMT=0%2e00&SHIPDISCAMT=0%2e00&PAYMENTREQUEST_0_CURRENCYCODE=USD&PAYMENTREQUEST_0_AMT=15%2e00&PAYMENTREQUEST_0_SHIPPINGAMT=0%2e00&PAYMENTREQUEST_0_HANDLINGAMT=0%2e00&PAYMENTREQUEST_0_TAXAMT=0%2e00&PAYMENTREQUEST_0_INSURANCEAMT=0%2e00&PAYMENTREQUEST_0_SHIPDISCAMT=0%2e00&PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED=false&PAYMENTREQUEST_0_SHIPTONAME=Frank%20Forest&PAYMENTREQUEST_0_SHIPTOSTREET=1%20Main%20St&PAYMENTREQUEST_
0_SHIPTOCITY=San%20Jose&PAYMENTREQUEST_0_SHIPTOSTATE=CA&PAYMENTREQUEST_0_SHIPTOZIP=95131&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=US&PAYMENTREQUEST_0_SHIPTOCOUNTRYNAME=United%20States&PAYMENTREQUEST_0_ADDRESSSTATUS=Confirmed&PAYMENTREQUEST_0_ADDRESSNORMALIZATIONSTATUS=None&PAYMENTREQUESTINFO_0_ERRORCODE=0
This expected answer contains PAYERID, FIRSTNAME, LASTNAME, SHIPTOSTREET,
SHIPTOCITY etc.
I tried calling the PayPal sandbox from java using
Apache HttpClient GET request
Apache HttpClient POST request
javax.net.ssl.HttpsURLConnection
java.net.URLConnection
I tried running the webapp in JBoss 7.1.1 on mac OS X and JBoss 7.2.0 on
win8.
The result is always the same. The payer information (name, address) is
missing when I call it from java.
Has anyone got an idea what is wrong?
How to run simple MYSQL query using rails
How to run simple MYSQL query using rails
I want run a simple MYSQL query using rails
"Select movie-title, movie-director from moving order by rating desc limit
5;"
I don't want all the overhead creating models. I just want to run the query.
What is the best way to do this? I cannot even connect
Here is my the code from my controller
ActiveRecord::Base.establish_connection ({
:adapter => "mysql2",
:host => "some-rds.amazon.com",
:username => "root",
:password => "root",
:database => "blah"})
This will generate this error ActiveRecord::ConnectionNotEstablished
thanks
I want run a simple MYSQL query using rails
"Select movie-title, movie-director from moving order by rating desc limit
5;"
I don't want all the overhead creating models. I just want to run the query.
What is the best way to do this? I cannot even connect
Here is my the code from my controller
ActiveRecord::Base.establish_connection ({
:adapter => "mysql2",
:host => "some-rds.amazon.com",
:username => "root",
:password => "root",
:database => "blah"})
This will generate this error ActiveRecord::ConnectionNotEstablished
thanks
Subscribe to:
Posts (Atom)