One-to-Many in Sonata admin bundle performence - sonata-admin

I am using symfony and sonata admin bundle.
I have a one-to-many relationship. I am using sonata_type_collection from the admin class.
I have about 5000 entries in the collection. This is comming up as a dropdown list with 5000 entries(normal).
so entity_1 has a 1 to many relationship to entity_2(5000 entries in db)
I have 3 instances of entity_2 to my entity_1, so i get 3 drop downlist of 5000 each.
My app is taking about 20-30 seconds to load because of these 3 drop down list.
If i remove the reference to entiy_2 from entity_1 admin class my app takes about 5 seconds to load admin_1's page.
Does anyone have a clue what i can do to improve performence?
Thanks

Have you tried autocomplete field type:
https://sonata-project.org/bundles/admin/master/doc/reference/form_types.html#sonata-type-model-autocomplete
It won't generate dropdowns until some values is provided. Not sure if it suits for your case, as you haven't mentioned anything about your models, relations etc.

Related

Query with multiple ancestors in Google App Engine(GAE) JAVA

I have two entities 'user' and 'comment'
I create comments and set ancestor path as user
I added 5 users and some comments per each user.
What I wanted to do is, filter out comments only for two users within one query with limit and offset
I have searched in Google App Engine documentation, but I couldn't find any answer for this.
The reason for not finding anything is that this is not possible by design.
An ancestor query is always a query by id. If you need to find all children of multiple ancestors you have to add the parent id as an indexed column in your child entity and filter by that column.

Database design - Managing documents

I asked a more generic question yesterday and done some work based on this. This question is more to the point in regards to something I am trying to work out.
So my application has a departments table to handle departments. So I am able to make different departments within my application such as Marketing and Finance.
The problem is, I know what departments I need to make, and these will be created beforehand (but I have made it like a CMS so an admin can edit departments etc). With the departments created, I envision something like this
So a user can choose the department from a dropdown (remember, this is after departments are created). When they do this, the document dropdown should populate.
This is my problem, how can I associate specific documents to a department? Each document requires different inputs, so I would imagine they need to be different tables? At the moment I have
But this doesnt really solve my problem whereby I can state that the Marketing department has a Brief document and Overview document.
How could I go about doing this seeing that I do not specifically have a table for each department? Would I need to create one for each department?
Thanks
You can do the following:
If the variety of the document's information you need to store is to large
create a table which has 5 columns:
id,department_id,crated_at, updated_at, property
so for each property you will have a record in the table e.g:
id department_id crated_at updated_at property
1 454 2015-08-20 2015-08-22 x:34
2 454 2015-08-26 2015-08-26 z:234
3 934 2015-08-25 2015-08-26 y:45
This way you won't need table for each document type
EDIT: another option is adding one column for property name and one for it's value
id,department_id,crated_at, updated_at, property_name, property_value

Multiple datasources for one model in CakePHP

I have a very interesting problem in relation to CakePHP. I have a client that is currently selling products on eBay, and wants to start selling products on their own website as well. There would, then, be two separate sales avenues: (1) eBay, and (2) website.
However, they do want to have a seamless website experience for their customers. Basically, they want their current eBay sites to be categories within their current website, and their current eBay auction items to be searchable on their website.
A simple CakePHP website would have two tables: products and categories, with the simple table relation of "products belongsTo categories" and "categories hasMany products". How would I then add in the eBay categories and products? Basically, I want the http://site/products/index to return a list of ALL products, both in the products table and on eBay. I want http://site/categories/index to return a list of all defined categories in the categories table plus the categories items are listed in on eBay.
eBay has a very good pretty much real-time request query API, so I've been thinking about an option to do this, but am wondering if there is a better way... I don't think this option would work very well with PaginatorComponent...
Method:
(1) In beforeFind, capture the request parameters and save to a persistent variable
(2) In afterFind, make a request to the eBay API based on the request parameters, then manually add the results to the $results array.
Again, I think this would work for basic find operations, but I'm not sure this would work with pagination because I'm not sure how to deal with, say, a 20 item page limit (i.e. How do I deal with a page 2 when only 18 items from the database were on page 1, and now on page 2 I need to start at 19 instead of 21 from the database?)
Is there a CakePHP syntax that I'm overlooking here, or do I just start working on coding for all of these eventualities?
I'm coding on a CakePHP 2.6.0 platform.
Thanks so much for your help!
One possible approach would be to read all the products from each datasource, sort them in memory and paginate from there. The number of products would of course play a major role here.
A second one, if the number of products does not change too often, would involve a background process to retrieve their ID, and the most essential data, from eBay and write them in the common Product table, flagging the rows created.
Then Paginator can then show your results, but other fast-changing data can be retrieved on-the-fly from eBay for the flagged products while composing the page.

Handling Onload events to add server side logic in ADF

I want to know how do we handle onload event so that we add some business logic once a view is loaded.
In brief this is what i want to achieve -
I have a entity object which i am showing as editable ADF table. Now once the page is loaded and I want the table to show at least 4 rows no matter how many rows exist in Database table. For example, if database table has 2 entries then ADF table should show those 2 rows and additional blank 2 rows in ADF table. And if the database table has 6 rows it should show 6 rows in ADF table.
How to programmatically handle this functionality. What functions and methods i need to override or add.
Any help is appreciated.
Thanks.
There are multiple ways of doing this, including doing this in a method call in the taskflow before you reach the page.
Some options:
https://blogs.oracle.com/adf/entry/an_epic_question_how_to

App engine datastore, query sorted by fk attribute

I'm working on the datastore of google app engine, and I'm developing an app for manage events.
I have 2 entity:
- user
- event
- attribute eventDate
A user can follow one or more event, so I create the link table
- UserEvent
-User key
-Event key
My problem is that I would like to have a list of the events followed by the user, ordered by eventDate.
How can I do?
I found 3 solution, but I don't like anyone...
Query on all the event ordered, and then iterate and choose only the
one with has one occurency on UserEvent (I don't like because
probably I will have thousand of event, but a user follow only
few..)
Query on all the user event (filtered by userKey) and put the result
in an ordered list (I don't like because I have to load all Event at
once, without pagination)
Add in table UserEvent the attribute eventDate (I don't like because
if an event has 3000 followers I have to do 3000 update...)
Thank you
Alessandro
If you really don't like such denormalization, consider using CloudSQL.
If you always query events for a given user, you can consider storing a ListProperty of Events in the User entity.
- user
- attribute eventList []key
You will be limited by the maximum size of an entity (currently 1MB) and if the list is indexed your're limited to 5000 entries.

Resources