MVC3 how to optimize the get and post - asp.net-mvc-3

Just an introduction of my code...
I have a view that consists of
-details of an item
-questionnaire
The questionnaire part has:
-series of questions
-answer choices (can be single choice or multi-choice)
so in my viewmodel, I have like a mainviewmodel to contain the details of a certain item and inside that mainviewmodel, i have a property that maps to a questionnaireviewmodel.
questionnaireviewmodel:
- questionid
- answertype (single or multi-choice)
- answer_score
- answer_text
mainviewmodel:
- detailid
- name
- status
- questions : list
so in the view, i created a loop to display each of the questions and when a user click saves, it saves the answers to a database.
the problem..
The problem I have now is that its taking aorund 11secs to load the page and around 18 seconds to do the saving. Note that the questions count i have in my page is around 8 only. I noticed that my page size is sized around 630kb+ maybe because of the many hidden fields i have in my page to keep the details of the questions.
Do you have any suggestions quick or long term(rearchitecture) on how I can improve performance? I'm thinking of doing ajax call so as not to post the whole page on this but would love to hear your feedbacks. Thanks.

It's not easy to give you specific suggestions on rearchitecture before analyzing the whole application and reviewing the whole source code. My recommendation is doing profiling. Justly click VisualStudio2010 menu 'Aanlyze'-'Launch performance wizard'. Start you application in release mode and record your actions. Finally the profiling report will tell you the hot lines that takes most time of 11s. Hope this helps.

Related

Laravel Query issue

I have make the survey site. User post the question and other user ans them the question.My code work perfectly but the views is not good. All the question shows the user.How we can one by one show the question. User press the next button then show the next question if press the previous button show the previous question.
Any Idea for this problem Or suggest me related site
The easiest way to do this is with Javascript or similar.
But, I too did find this way interesting as well using php only and please check whether they could help.
How to display only one data at a time in an online quiz
OR
One quiz item per page (php/mysql quiz program)

Backbonejs: updating subviews and views when needed upon route navigation

we have a small questionaire application,
and 1 of the main sections is the questionaire itself.
it has a big view for some general templating, introduction and title etc
and it has subviews per question (with next and previous buttons)
we decided to use routing, because from several places one can jump to a specific question
so we use /ivr/4 to show question 4, and /ivr/overview showing the final overview.
so in a way you go from /ivr/1 to /ivr/2 ... to /ivr/overview
now, if one comes from /ivr/1 and arrives on /ivr/2
the big view is there, and it should only update the question to the right question
but when you arrive from /home to /ivr/2
the big view is not loaded, so one should first open the questionaire and then load question 2
currently i have it always rerendering the big view
which works, but is lots of overhead and i would like to refactor this to a better way.
can anyone give me some guidance as to how i would structure routeActions and or views
to only update the big parentview when it actually needs to, and do the question view only, if the parent view is already there.
do i need events?
or would i go with partial routes?
any tip is welcome.
I think both of your proposed solutions sound workable. If you go with events, I'd recommend using the event aggregator pattern to facilitate communication between your views. This seems like the simpler option to me.
The other solution, partial routes, might be more involved. Check out the Backbone.Marionette plugin, which was designed to help manage complex view manipulation.

Drupal 7 - Views, loaded by Ajax

Two years ago I made a website to learn Flash, but these days Flash is loosing it's popularity. (the website never went online, was just for testing) Now I want to try making this test website with Drupal + Ajax...
Take a look at the Flash website
I have a collection of handbags, with different types and sizes. So I use taxonomy for that. (content type: handbag, with taxonomy terms "type" and "size" - small, medium and large)
The visitor should choose a type in the navigation. (Silver Medallion or Silver Jewel) Then he sees a page (made with views) that shows all available sizes. (The type 'Jewel' doesn't have sizes, so this type should show all bags.)
After the visitor clicks a size, he sees all available items of that type and size. With views, this is quite simple... But now I want to do this with Ajax, so the page doesn't have to reload... I also want the path to change, so people can add a page to the favortites.
I found an answer that helped me a bit further, but I have no idea where to put the code...
Code that helped me out... a bit
I think you need to create a custom module to create the view and add the configuration in setting file, then create a js file and add to drupal project.
Take a look at this. It seems to provide what you want: http://drupal.org/project/quicktabs/

How do you prevent gaming of page views?

Say I have a site with pages. Pages are ranked based on the number of times they have been viewed. It is good for a page to be highly ranked because it will make it show up higher in my search results. Hence, the author of a page may try to game the system to increase that particular page's views.
So how do you prevent that while still keeping a quasi-accurate count?
I have come up with the following "scheme":
A user can only affect the page view once per session. This is what I would normally expect. If a user returns to the site later and views the page again, it should count as another page view.
The problem is that this makes the page view increment vulnerable to a script that clears its cookies before each request. The easiest solution to this problem would be to save the ip-address and only allow the same ip-address to increment page count once. This however has several major drawbacks; First of all, this would potentially take up a lot of storage, and second of all would prevent users on big LANs from incrementing page count. Lastly, a user cannot revisit a page and increment the page view more than once from the same ip. I can live with that, but would rather live without it.
The best method I can come up with off the top of my head would be to save the last X ip-addresses, and not let anyone from these ip-addresses affect the page view count. This would effectively stop any (simple) script from raising the page view count. Furthermore it would probably be a good idea to add a delay to the display of actual view count (basically keeping two counts and a datetime field for when the "display" count was last updated with the "actual" count, something I believe is done on the SE sites).
This is not a perfect solution, so I would be happy to hear your suggestions and/or comments.
Don't prevent: monitor and handle.
I would use a very different approach. Let the page views stay the same, but have reporting in place to looks for view-gaming. If a page gets gamed, you can find out who is responsible, give them a warning and a page-view penalty. If it continues, ban them.
I think that you should consider the reported characteristics of the browser as well. Browser fingerprinting has been done before and is well publicized. You can then figure out some pretty advanced heuristics on determining whether the same user is trying to game you. But don't publicize that you're using browser fingerprinting of course. Also, it won't stop incognito mode, but I'm just trying to give you one more avenue of thought to follow, in addition to your current IP oriented strategies.

MVC (model-view-controller) - can it be explained in simple terms? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I need to explain to a not-very-technical manager the MVC (model-view-controller) concept and ran into trouble. The problem is that the explanation needs to be on a "your grandma will get it" level - e.g. even the fairly straightforward explanation offered on MVC Wiki page didn't work, at least with my commentary.
Does anyone have a reference to a good MVC explanation in simple terms?
It would ideally be done with non-techie metaphor examples (e.g. similar to "Decorator pattern is like glasses") - one reason I failed was that all MVC examples I could come up with were development related.
I once saw a list of pattern explanations but to the best of my memory MVC was not on it.
Thanks!
How about this - off the top of my head, hopefully it works for you.
MVC can be metaphorically related to a TV. You have various channels, with different information on them supplied by your cable provider (the model). The TV screen displays these channels to you (the view). You pressing the buttons on the remote controls affects what you see and how you see it (the controller).
I was watching TV, so I got some inspiration from there!
I don't trust metaphors. But it's not hard to explain it:
the Model is the part of the code that knows things
the View is the part of the code that shows the things the Model knows
the Controller is the part of the code that gets commands from the user and tells the View what to show and the Model what to know.
The best way I describe it would be:
The Model is the data source. It's your database storage, it's the
code needed to add/remove/update/change the information you
warehouse.
The View is the part the user sees and interacts with. An HTML
page, an application window.
The Controller is the code that marries the View to the Model. If
you clicked a "Delete" button, it handles the business logic and
rules (are you the authorized person to delete? is it a deletable
record, etc).
The View doesn't need to know anything about the Model. The Model doesn't need to know anything about the View. The Controller is what marries the information source (Model) with the output (View).
Think of it in terms of video games. Way back when - there were tons of different video cards and how they worked. Games needed all kinds of code to talk to them. You had to choose what kind of card you had before you could play the game. Game developers had to create code for different video cards.
Along comes something like OpenGL or DirectX -- and it acted as the middle-layer between them. Game developers could write to the DirectX interface -- instead of different card's instruction sets. It freed game developers from having to know about the specific video card. It freed card makers to be able to design to the DirectX instruction set.
In this case - you playing the game is the View, DirectX is the Controller, and the Model is the video card.
M-V-C Think of it as: "Order Details (including Customer & Employee info)", "HTML/ASP Form (to display the OrderDetails)" and "Order details service class (having methods to SaveOrderDetails, GetOrderDetails etc.).
The Model (Data Class e.g. OrderDetails)
The data you want to Display
The Controller (Service class)
Knows about the Model (Order Details)
Has methods to manage the Model
And as such can be unit tested Its Single Responsibility is to manage the OrderDetails CRUD operations.
It knows NOTHING about the View
The View (ASP Page)
Displays the Model (OrderDetail's ViewData).
It has to know about the Model's structure so it can correctly display the data to the users on screen.
The View's structure (style, layout, HTML etc., locale) can be changed at anytime without it changing anything in the application's functionality.
And as such, many Views can display the same Model in many different ways.
In multi-tenant web applications, Customer specific Views can be stored in a database table and displayed based on Customer information
Tell "your grandma" that you are the model (you are doing the work), he is the controller (i.e., middle manager), and the view is like marketing, they get all the credit.

Resources