I've created a Query Loop on a Post. It works fine. If I change to Code Editor, I see there is a queryId:{int} which is generated. I'm wondering where that int id is coming from each time I add a new Query Loop. I have looked in the db to no avail (yet).
Why I'm asking. I am duplicating a post with that same Query Loop. When duplicated, the queryId remains the same. And it seems to be okay that I change the filtering (as in it doesn't change the filtering on the original that I duplicated from). The config for the query itself is in the Post ... which again makes me wonder why it needs this id?
I have assigned a random {int} too to see if that would break things, but it didn't.
Any idea where that id is stored in the db?
The queryId attribute is used to differentiate multiple query loop blocks on the same page for pagination. When you go to the next page using a pagination block in the query loop block, the queryId is included in the URL query (?query-{id}-page=2) to tell wordpress which query loop block you want the next page of. The ID is generated when the block is created, and stored only in the block attributes (the comments you see in code view), not in the database.
https://github.com/WordPress/gutenberg/blob/wp/5.9/packages/block-library/src/query/edit/index.js#L79
So yes, it SHOULD be different for each query loop block on a page if you expect pagination to work for each of them independently.
Related
I am trying to fiigure out how exacly I should make sure that I only fetch the most recent x posts from the DB.
My current fetch methods work as follows:
GetPeopleIFollowAnd loop over each UID
For each UID fetch his posts
By doing this however I cant efficiently (quickly) fetch only the most recent x posts. How can I do this?
Some possible ideas I have:
Create a new Node which, every time that one of your followers makes a post, they will be added beneath your UID with a timeStamp. So When I fetch I loop through this FollowersWhoCreatedRecently for each UID and only do so for the first 10
Problems I see with the above solution is that if a user were to have a millions of people following them this would be horribly slow when it comes to updating every single one of those million
I have found this which seems like it may be of use. How could I use this?
My DB structure for posts is as follows
Post
UID
postID
Media
media
image: URL
Based in a follower structure like:
WhoFollowsMeNode/UID/uid: true
I would have to, every time a user posts, loop through this list where for each user I would add the post to there timeLine... That seems undoable, and yet that what it seems they are doing here.
On Realtime Database, you can make use of limitToLast() method, you can then pass how many elements you want to bring, this method will fetch the last information that has been added in a node, since the documents are ordered with a timestamp, if you fetch them with limitToLast(10) you can get the last 10 posts of a user.
If you are working with a List of posts, you can invert the list when showing it to the user, doing this, you will see the most recent data first and the old data below.
I have a Collection of Posts and a Collection of Users. Posts have certain attributes which are irrelevant for this, but they also have one attribute called tags right now its an array with certain words.
A User can follow certain Tags so he has a attribute followedTags which is also an Array right now that contains the Tags he follows.
Now one of the use cases for this is a User Feed to Show only Posts with Tags he follows, the Problem is that I only found methods to query this for ONE Attribute at a time(in Arrays). Since I dont wanna run 20 Querys for 1 Feed (For example if the user follows 20 Tags) I thought maybe I could make a smart change in the data modell itself, any suggestions?
Problem is that I only found methods to query this for ONE Attribute at a time(in Arrays)
If you try to chain multiple whereArrayContains() methods, you're most likely getting the following error:
Caused by: java.lang.IllegalArgumentException: Invalid Query. Queries only support having a single array-contains filter.
So unfortunately Firestore can only allow a single call to whereArrayContains() method in query.
Since I dont wanna run 20 Querys for 1 Feed (For example if the user follows 20 Tags)
If you have a reasonable number tags, you can create each tag as a separate property. In this case, it is allowed to call Firestore Query's whereEqualTo() multiple times.
If this is not the case, then you should consider augmenting your database structure to allow a reverse lookup by creating each tag as a seprate object (document) in a tagCollection. Under each document you can create a new collection named tagPost in which you should add all the posts that are labeled with a specific tag.
I'm trying to make a query against the table HcmWorker and related.
But i want to figure out how to get the result of the display method HcmWorker.primaryDepartmentName() into it's own field in my query.
I also tried creating a view to execute the function via a ViewMethod but that doesn't seem to work as ViewMethods only inject code into the final query against the view.
I'm NOT making a form. The end result has to come through the QueryService.
Sorry, but what you are trying to do is not possible.
You could calculate a non stored field in the postLoad method, but that would impact every access to your table, and it would most likely not work in the context of a query service.
Currently, I'm using tablepress to output different info using a table format. I want users to be able to add to existing information. I need a form in wordpress that saves user posts to these different tables. How should I go about this? Sorry if I sound stupid but I'm soft on html.
Thanks.
If you want to insert in posts table using custom form, you can use wp_insert_post().
This function inserts posts (and pages) in the database. It sanitizes variables, does some checks, fills in missing variables like date/time, etc. It takes an object as its argument and returns the post ID of the created post (or 0 if there is an error).
Reference : http://codex.wordpress.org/Function_Reference/wp_insert_post
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