Ravendb - 'selecting' collection entities from parent entities - collections

I am trying to create an index in raven that will (to all intents and purposes) project all comments on all blog-posts that were created by a specific user. At present I have managed a map statement, which only returns the posts that have comments.
from post in docs.Posts
from comment in Hierarchy(post, "Comments")
select new { comment.User, comment.Text }
At the end of this, I will want to page through the comments, so I need to get a flat list of all matching items.
Thanks

What is the problem that you have run to?
You are projecting the comment data out, you need to tell RavenDB to store the fields, but you can now query it just fine.

Related

Firestore(Firebase) store big list

I have one question for the store of big list in firestore (using flutter).
I have a database like this:
--DataBase
------Post
---------Comment
And each post/comment must store the list of user who liked/add fav.
In a first time i have create two list in my collection Post/Comment
But I know that the solution is not good, because the size of a document is limited
So I thought about a second solution, which consists in adding a collection "userData" in the Post / Comment collections and for each user create a document containing the data. Like this :
But the second solution bothers me. Because when the user loads the Post list and the comment List, for each post/comment I will do an additional query to find if the user already likes/add fav.
So if I have 50 comments per post and if the user looks at 100 posts, it generates 10,000 requests (100 * 50 * 2), and that per user.
I am afraid that the price of these requests does not cover the gains of the application.
So, is the second solution the recommended solution? Is there another solution ?
Thanks
I would use subcollections for this and simply not display the list of comments (or just show the latest comment) when the user is going through the list of posts. Once the user interacts with a post then paginate or create an infinite scroll of the comments collection using query-cursors

How to add/save temporary table on form

We created special form to creating purchase prices for vendors.
New form has almost the same fields as original (so we used PriceDiscTable), but the record/datasoruce was set as temporary table. After user filled mandatory fields will click button, (extra logic behind) and record will inster to database (real priceDiscTable).
The idea was to grand access to trade prices for users that not necessarily has access to purchase prices. In theory everything was ok, but when user with no access to PriceDiscTable open new form, error was shown "Not enougt right to use table 'Price agreements'".
We try set the AllowCheck to false in formDatasource but this only allow us to open the form, but user still cannot add or modify records.
Is there any way to force system to allow user to write data in the temporary table?
Disabling security key or grand access to real table is not an option.
Duplicate table and create with same fields is nuisance (if we use same table we can use data() method to assign fields)
I think that creating a new temporary table with [almost] the same fields would be the best solution.
If the only reason you oppose to this approach is that you wouldn't be able to use data() to copy data from one table to another you can use buf2BufByName() as described here: http://mybhat.blogspot.co.uk/2012/07/dynamics-ax-buf2buf-and-buf2bufbyname.html
You can use RunAs to impersonate another user...perhaps a system user. I don't entirely follow what you are trying to do, but it sounds like this solution would work for you if you know exactly what your custom code is doing and is capable of.
See Classes\AifOutboundProcessingService\runAsWrapper to see an example.
You will not be able to display the PriceDiscTable without giving the user at least "view" access or editing Classes\FormRun to somehow bypass the security key, which is kernel level so it's also not possible.
I agree with 10p where you should create a temp table and then create a custom method handler combined with buf2bufbyname() or buf2buf().
Another option you can screw around with, if you REALLY want to use .data() is using a Common as the datasource. You could add the fields you want on the grid with the common, then you can pass a common back/forth. This has a good amount of form setup to get this working, but it could produce what you want eventually I think.
static void Job8(Args _args)
{
Common common;
salesTable salesTable;
;
common = new DictTable(366).makeRecord();
select firstonly common where common.RecId == 5637145357;
salesTable.data(common);
info(strfmt("%1 - %2", salesTable.SalesId, salesTable.SalesName));
}

Implement "follow person, post" feature in asp.net mvc

In any social network, you can follow a person, a post or anything, everything you followed will be displayed in your wall, now I wanna implement the same feature in asp.net mvc, but I have problem on design table to query all following things of a user. This is tables I designed:
[User(id,name,email,password)]
[Following(id,personId,followingId,source)]
[Post(id,title,description,authorId)]
So when a user followed other user,a new record will be pushed on Following table with followingId is userId, and source is "User" table, the same as with following a post with followingId is postId and source is "Post" table.
The problem is when fetch data from what your following, the query join many tables to return result if user followed more things than a Post, and Other User (such as a Tag, a Topic...). this will be not good performance and query time to return data to user.
Do you have any idea about this ? I'm very appreciate to hear your solution, thanks a lot!
Your database design is flawed, instead of one "link" table with a string to identify where the "Followed thing" resides makes it hard to query effectively.
Instead you need one link table per thing linked. SO in your simplified example you might have
[User(id,name,email,password)]
[Post(id,title,description,authorId)]
[UserFollowingUser(id, userId, followedUserId]
[UserFollowPost(id,userId,postId)]
Therefore to get all users following a post, or all posts followed by a user, or get all users following a particular user, or get all users followed by a particular user is easy as pie.

Grails: DELETE in autobinding 1-N object arrays

In Grails you can have 1-N object relationship and you can manage the many side on the same page as the one side like this:
Author has many Books
Client side:
input name=authorName
input name=books[0].bookName, hidden name=books[0].id
input name=books[1].bookName, hidden name=books[1].id
Server side:
Author(params).save()
This will save (or update if id is not null) both the Author and the Book collection. Which is fantastic!
But is there a way to also issue a DELETE for the book if for example books[1] no longer exists or it's id has been set to null?
the best thing is to handle this on the client. dont send the empty records and re index the new records you need to save

How do you avoid the n+1 problem with SubSonic?

Ayende has a blog post detailing how to combat the "n+1" problem in nHibernate. In essence, the problem is this:
Assume you have two tables, "BlogPosts" and "Comments" with a one-to-many relationship between them (i.e. each BlogPost can have multiple Comments). Now, let's say you want to execute the following nested for loop:
foreach (BlogPost post in blogposts)
{
foreach (Comment comment in post.Comments)
{
// Do something
}
}
From what I understand, the classes that SubSonic generate are lazyload by default (I don't want to turn this off completely because it's useful in most circumstances, just not this one). That means that every time the inner loop is executed (i.e. when post.Comments is accessed), a separate query must be sent to the database to retrieve the comments.
So if you have 80 blog posts, that's 1 query to get the list of blog posts, then 80 queries to get the comments for each of them. If the comments were eager loaded, however, this would be reduced to 1 query.
Is there any way to combat this problem in SubSonic currently?
Unless you create a query to select from Comment based on post IDs, I don't think there's a way to combat it. This would get you down to two. One query to select the post IDs you want, then another to get all the comments for that list of post IDs.
I think what you should do is create a partial class method that will get all the comments. Not so clean but should work.
I too use partial classes and load related table classes like so:
Partial Public Class Book
Private _Author as Database.Author
Property Author() as Database.Author
Get
If _Author is nothing then
' Load the author class here.
End if
return _Author
End get
Set
'....
End Set
End Property
End Class

Resources