Jump to content

set_relation_n_n very slow

set_relation_n_n slow many records

  • Please log in to reply
2 replies to this topic

#1 rdal



  • Members
  • Pip
  • 1 posts

Posted 25 July 2012 - 08:42 PM

I have medical system that runs with Code Igniter and Grocery CRUD.
I have a large set o drugs stored in drugs table, over than 10K.
I also have a set of patient prescriptions, and in each prescription I may have several drugs.

The problem occurs when I try to add a new patient prescription, because I use set_relation_n_n to let users add multiple drugs to a prescription, and as I said before my drugs table has over than 10K records. "Add screen" takes too long to load, and the browser launches a dialog that asks if we want to stop script or continue executing. After 3 dialogs like that, "add page" finally loads, with all drugs available to choose.

I have already tried to change indexes in drugs table, but no luck until now.
Is there a way to fix this issue?

Thanks in advance,
Rafael Donato.

Attached Thumbnails

  • Screen Shot 2012-07-25 at 5.40.41 PM.png

#2 xxaxxo


    grocery CRUD Expert

  • Members
  • PipPipPip
  • 71 posts
  • LocationBulgaria

Posted 26 July 2012 - 07:14 PM

10k rows is a bit large. The problem is not in groceryCRUD. The way things work now for you is that groceryCRUD queries your relational db and add's all those rows to the multiple select menu - you will have that problem whenever you try to load that amount of data into a simple select menu aswell.
I have 2 suggestions:
1: use callback input/edit field and try to make a simple input filed with a typeahead (suggestion) js (i'm not 100% sure what it's called i'm using gccrud with twitter bootstrap and in bootstrap it's called typeahead ) - also I'm not sure if it will speed up the things because most of those scripts usually require an array with elements to suggest when inputing which will also require a big query.
2: add an action that calls another function in your app that doesn't use groceryCRUD to add the drugs to the users when inputing them. Instead of querying the db before load , and trying to display all those 10k into the view - try querying the db multiple times but displaying only small parts of the data.

#3 Hoergold2



  • Members
  • Pip
  • 3 posts
  • LocationBerlin

Posted 19 September 2012 - 03:17 PM


I myself also found that the CRUD does not work usable enough (browser goes off for some time etc.) if I try to use the n:n-relation on something like "authors" to an "book".

There are many, many Authors in the Author-table (>60k), but just to e.g. edit a Book (looking up the related Authors like 1, 2 or 3 in the relation-table and then showing the names (better would be: being able to build something to show "Name, First Name" because many Authors have the same last Name)) should not consume so much time etc.

It seems every single Author is loaded somewhere in the background - and that is not neccesary and seems to be the problem.

Does anybody has an idea about that?


Also tagged with one or more of these keywords: set_relation_n_n, slow, many records

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users