Taking too long to retrieve and display the result in the telerik grid. - database

I have a MVC application in which I need to display the data from 3 tables. I am using entity model for it. Out of these, in 2 I have made the association:users and payment table.
And 3rd table month_<monthid> is created every month to store the users to whom the magazine is sent. The table name month_<monthid> is generated dynamically by selecting the month so in order to fetch the data I have used ExeuteStoreQuery. For small amount of data the listing is fast but for large amount it is very slow.
Now I have created a class to bind to grid which will include all the fields from the 3 tables to display.
But here when I am getting the large volume of data about 12000 then it is taking about 30 min to go through the loop and assigning the data to the class object and then adding to the list of the result which is finally binded to telerik grid.
I am hereby attaching the sample code using a link. Is there any direct way to bind the query result of joined tables to grid instead of going through the loop and preparing the list for the model class I think that will save time.
The code block of preparing the list using the Executestorequery is under the function GetuserList().
foreach (var r in result)
{
Result objresult = new Result();
var paymentresult = from sub in dtpayment.AsEnumerable() where sub.Field<int>("user_id") == r.user_id select sub;
if (paymentresult.Count() > 0)
{
objresult.amount_paid = paymentresult.FirstOrDefault().Field<decimal>("amount_paid");
objresult.magzine_id = paymentresult.FirstOrDefault().Field<int>("magzine_id");
}
objresult.address=r.address;
objresult.email=r.email;
objresult.name=r.name;
objresult.user_id=r.user_id;
objresult.month= smonth;
lstresult.Add(objresult);
}
This code block of for loop is taking very time where I am using ExceuteStoreQuery.
But I have observed that simply by joining the users and payment table using LINQ query to get all the 12000 records i.e no involvement of month table the result is appearing faster.
So,can you suggest any way to improve the performance of my application?
Also include the database structure with the sample code.
Below is the link to sample
http://sampletestone.s3.amazonaws.com/magzine.7z?AWSAccessKeyId=AKIAINHDRCMKC5GUSNFA&Expires=1303583399&Signature=8o8Wn6UNjbEl3dIyipAX9xH29Hg%3D
supriya

Nobody in the world wants to see 12,000 records. You should look at implementing paging & searching functionality.

Related

Anylogic: How to create plot from database table?

In my Anylogic model I succesfully create plots of datasets that count the number of trucks arriving from terminals each hour in my simulation. Now, I want to add the actual/"observed" number of trucks arriving at a terminal, to compare my simulation to these numbers. I added these numbers in a database table (see picture below). Is there a simple way of adding this data to the plot?
I tried it by creating a variable that reads the database table for every hour and adding that to a dataset (like can be seen in the pictures below), but this did not work unfortunately (the plot was empty).
Maybe simply delete the variable and fill the dataset at the start of the model by looping through the dbase table data. Use the dbase query wizard to create a for-loop. Something like this should work:
int numEntries = (int) selectFrom(observed_arrivals).count();
DataSet myDataSet = new DataSet(numEntries);
List<Tuple> rows = selectFrom(observed_arrivals).list();
for (Tuple
row : rows) {
myDataSet.add(row.get( observed_arrivals.hour ), row.get( observed_arrivals.terminal_a ));
}
myChart.addDataSet(myDataSet);
You don't explain why it "didn't work" (what errors/problems did you get?), nor where you defined these elements.
(1) Since you want both observed (empirical) and simulated arrivals per terminal, datasets for each should be in the Terminal agent. And then the replicated plot (in Main) can have two data entries referring to data sets terminals(index).observedArrivals and terminals(index).simulatedArrivals or whatever you name them.
(2) Using getHourOfDay to add to the observed dataset is wrong because that just returns 0-23 (i.e., the hour in the current day for the current model date). Your database table looks like it has hours since model start, so you just want time(HOUR) to get the model time in elapsed hours (irrespective of what the model time unit is). Or possibly time(HOUR) - 1 if you only want to update the empirical arrivals for the hour at the end of that hour (i.e., at the same time that you updated the simulated arrivals).
(3) Using a Variable to get the database value each hour doesn't work because a variable's initial value is only evaluated once at model initialisation. You want an hourly cyclic Event in Terminal instead which adds the relevant row's value. (You need to use the Insert Database Query wizard to generate the relevant Java code for the query you need in the event's action.)
(4) Because you have a database table with specifically-named columns for each terminal (columns terminal_a and presumably terminal_b etc.) that makes it slightly more awkward. (This isn't proper relational table design where, instead of 4 columns for the 4 terminals, you'd instead have two columns for terminal_id and observed_value with a row for each time period and terminal combination.)
So your database query expression (in your Terminal agents) will need to use the SQL format (not the QueryDSL format) so that you can 'stitch in' the correct column name into the SQL.

Dataset from a Dataset in SSRS

I laid out the report, and I do a query that returns 30+ rows for a given period of time. One for each workflow. Now, I want to take that dataset (so the query only runs once) and define 6 datasets from it that filter it based on a single selected row. I will populate 8 boxes on the form for each of those datasets.
It appears that when you create a new dataset, it wants to go back to the datasource and ask you about all the data from that one again.
I was able to create a dataset that is a filtered view of the query and figured I could live with creating 6 datasets that ran the query each time filtering it differently each time. So, I need to do a 'copy' on the dataset and 'paste' it back in as a new dataset that is the same as the other one except with a new name.
I also need to set the default values for the Start/End date to be the 1st of last quarter, and the first day of this quarter. Is there a way to create calculated default values or do I need to do a query to return that?
if you are using table objects to create your report. you could use just 1 data set and add your filters to the table accordingly. just go to tablix properties>> filters tab.
for default values you can create expressions like for the first day of the current quarter:
=switch(DatePart(DateInterval.Quarter,today()) = 1, cstr(year(today))+"-01-01",
DatePart(DateInterval.Quarter,today()) = 2, cstr(year(today))+"-04-01",
DatePart(DateInterval.Quarter,today()) = 3, cstr(year(today))+"-07-01",
DatePart(DateInterval.Quarter,today()) = 4, cstr(year(today))+"-10-01")

Spilt the Main DB in Excel and Update the Values and Merge Them into one

I have a Database with 23000 Rows, Now we categorized as Like ( intrested, followup, not intressted) Now i want to create different work sheet for each category in that i have to update the sheet with other information which should be updated back in the main DB . Please help me how to do this.
I used Vlookup to do this but it is making my Workbook very slow in such a it take 1min to update value of single cell..
I tried Using Pivot Table to filter the values.since its dynamic when try to update the adjacent value to pivot table they are messing up.
in Sheet 1 I have the details of the Customer Like ( name,ph,email,CATEGORY(intrested,follow up, not interested), status, etc)in the status i have the last follow up.
now in the sheet 2 i have to extract one category(eg. intrested) with email,name, ph with that ill follow up with those client and enter the informtion of communication which should go back to the sheet 1 in a new column.

ExtJS and simple grid panel

I have a simple grid without direct connection with any database table. Just days of mounth in raws and persons in columns (let's say 31 x 20). In init procedures I read data from some tables, calculate and write them to this grid. Then I have to calculate lot of indexes, make some summs by raws, columns and part of them. Just statistics.
There's no problem with read from grid cells, this is very quick. I have a problem with writing data to the cells. E.g. procedure to fill this grid is the following:
days = Ext.getStore('StoreDays').getRange();
employees = Ext.getStore('StoreTeam').getRange();
Ext.each(days, function (day) {
Ext.each(persons, function (guy) {
tmp = day.get('from');
day.set('start_' + persons.data.prs_numer, start);
... and 4 additional SET operations to grid cells
});
});
And this procedure work more then 3 minutes!!! I don't know why and how to write good code to write this data normally. Be so kind and prompt me HOW!
Additionally I can't refresh e.g. every single raw after raw settings as I want.
Would you be so kind as to prompt me?
A cell update could mean the grid needs to refresh itself, so it does that 31x20x5 (31 rows, 20 columns, 5 times per cell) times!
Instead, do this:
store.suspendEvents();
// Do your update
store.resumeEvents();
grid.getView().refresh();

managing View Count of webpage

I am creating a jsp page where a single news item is shown, just like the single question on this StackOverflow page. I need to store the view count in a database.
I can simply increment the view count in the database this way:
`UPDATE table SET views=views+1 WHERE newsId=4458;`
But what if a single user hits that page again and again and again, say 50 times... In this case, my view count will not represent unique visitors to the site. How can I avoid this?
I want something like StackOverflow's view count system.
well one solution could be you make a new table (lets say its called views) with the following columns 'viewid' 'newsid' 'ipaddress' (obviously newsid is the foreign key)
every time someone visits ur website u check if his ip is already in that table for that news item.
Select count(*) AS count FROM views WHERE newsid=1234 AND ipaddress=123.456.125
if count equals 0 you insert like this
INSERT INTO views('newsid', 'ipaddress') VALUES(1234, 123.146.125)
Now when you want to fetch the viewcount:
Select count(*) AS count FROM views WHERE newsid=1234
you can enhance this by adding another column called 'count' and 'lastviewed' (type datetime) to the table views.
Lets say you allow every ip to be counted another time if the day doesnt match.
This way you will get a pretty accurate viewcount :)
to fetch the new viewcount you can simply use SUM
Select SUM(count) AS count WHERE newsid=1234
Good luck :)
You may want to reference spencer7593's answer here, where he basically suggests having both (1) a view count column, for quickly generating your webpages and (2) a separate views table, which records the user id and timestamp pertaining to each view, for the sake of analytics.
I would suggest that this views table could also be used to query if a viewing has occurred for a particular user with a particular piece of content in the last day (or week) when determining if the view count column should be incremented. By checking if a view of a certain item has occurred only in the last day (or week), the DB queries should be substantially less expensive while still protecting the integrity of your view count.
i say use a counter in Javscript . Increment the variable on body onclick. eg:
<script language=”javascript”>
function pageCounter()
{
var counter = 0;
counter = counter++;
}
</script>
<body onclick = “pageCounter()”>
and you can update the value with onclose ..

Resources