Sarbjit,
The index creation is something that you would do on the database.
Web2py doesn't have a role to play there.
For postgres: http://www.postgresql.org/docs/9.3/static/sql-createindex.html
________________________________________
Kiran Subbaraman
http://subbaraman.wordpress.com/about/
On Thu, 22-05-2014 7:53 PM, Sarbjit wrote:
Thanks Anthony,
I will try and will update.
I am new to web2py (web apps in general). Could you please provide me
an example on how to create index on table and once created, what
changes i have to do in controller, do i need to change the getResults
function?
-Sarbjit
On Thursday, May 22, 2014 7:39:48 PM UTC+5:30, Anthony wrote:
First, you can simplify your function as follows:
|
defgetResults():
tab2results
=db(db.Table2.Release==request.vars.release_name).select(
db.Table2.id,db.Table2.Year,orderby=~db.Table2.id)
returnSELECT([OPTION(r.Year,_value=r.id)forr intab2results],
_name='table2_name')
|
I assume request.vars.release_name is actually the db.Table1 id
field value, not a string name, correct (otherwise, the query
won't work)?
In the above, insert "return BEAUTIFY(db._timings)" before the
final return, and call the function directly in a browser tab,
with release_name=[some id] in the query string. See how long the
above query is taking in that case. If the query itself is taking
several seconds, try creating an index on the "Release" field.
Anthony
On Thursday, May 22, 2014 9:38:56 AM UTC-4, Sarbjit wrote:
Below is the snippets from code (I have changed few field
names as I can't share the exact field names)
--> Data base
db.define_table('Table1',
Field('Release'),
format='%(Release)s')
db.define_table('Table2',
Field('Release',db.Table1),
Field('Year'),
format='%(Year)s')
db.define_table('Table3',
Field('Manfucturer',writable=False),
Field('MID'),
Field('Year',db.Table2,writable=False),
Field('Engineer'),
Field('Location',writable=False),
Field('Title',writable=False),
Field('Description','text'),
Field('City',writable=False))
db.Table2.Release.requires = IS_IN_DB(db,db.Table1.id
<http://db.Table1.id>,'%(Release)s')
db.Table3.Year.requires = IS_IN_DB(db,db.Table2.id
<http://db.Table2.id>,'%(Year)s')
--> This function is called by AJAX on change of first option
in drop down
def getResults():
tab2results =
db(db.Table2.Release==request.vars.release_name).select(orderby=~db.Table2.id
<http://db.Table2.id>)
result = "<select name='table2_name'>"
for tab2 in tab2results:
print tab2
result += "<option value='" + str(tab2.id
<http://tab2.id>) + "'>" + tab2.Year + "</option>"
result += "</select>"
return XML(result)
No, I don't have an index for the table.
On Thursday, May 22, 2014 6:50:02 PM UTC+5:30, Anthony wrote:
Would still help to see your specific model code. Is the
field in question a reference field with a "represent"
attribute? If so, you'll get separate queries for each
item in order to lookup the represent value. How many
records in the table? Do you have an index on the field
being searched? If you execute the same query in a
separate DB client, how long does it take?
Anthony
On Thursday, May 22, 2014 8:37:55 AM UTC-4, Sarbjit wrote:
Hi Anthony,
Code is almost identical to the code posted in slice
with change in field names and number of records. Only
additonal difference is that I am using "orderby" in
the query before returing the results.
Surprisingly, sometime the result appears fast (within
2-3 seconds) but some time it takes long time to
populate it.
-Sarbjit
On Thursday, May 22, 2014 4:46:55 PM UTC+5:30, Anthony
wrote:
Would help to see some code. 4-5 seconds sounds
much too long.
You might also look into
http://dev.s-cubism.com/plugin_lazy_options_widget
<http://dev.s-cubism.com/plugin_lazy_options_widget>.
Anthony
On Thursday, May 22, 2014 12:17:42 AM UTC-4,
Sarbjit wrote:
Hi,
I am using cascading drop-down based on the
slice posted on
"http://www.web2pyslices.com/slice/show/1526/cascading-drop-down-lists-with-ajax-2
<http://www.web2pyslices.com/slice/show/1526/cascading-drop-down-lists-with-ajax-2>".
In my application, the number of sub-records
for drop-down are typically in range of 50-60,
so every-time I change the first option in
drop down, it takes significant time (around
4-5 seconds) to populate my second drop down.
I was wondering if there is a way to make this
fast by means of caching or by storing the
data for all the records the first time when
user logs into the system and then using that
data. Can some one please comment on how to
address this problem and if possible, an
example would be helpful.
-Sarbjit
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google
Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to web2py+unsubscr...@googlegroups.com
<mailto:web2py+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.