Reputation: 337700
I have a storage table which is an index of users who follow another specific user. To do this I have set the PartitionKey to the id of the user being followed, and the RowKey to the ticks of the date they followed, as per the guide on this post, with the id of the following user appended to it. This is working great. Here's an example of what it looks like.
// FollowerIndex
PartitionKey RowKey
56138dad-e2db-43ac-8ffe-eac4846bf01a 2519471107153765942_31d4d0e5-2e48-489f-99fd-ead58a5fd480
56138dad-e2db-43ac-8ffe-eac4846bf01a 2519471107153765942_32fd17ec-fac2-44f8-986e-4e1fc8a05751
56138dad-e2db-43ac-8ffe-eac4846bf01a 2519471107153765942_f9816107-23ea-4ed7-a900-7465c0d10f50
f9816107-23ea-4ed7-a900-7465c0d10f50 2519471107153789651_32fd17ec-fac2-44f8-986e-4e1fc8a05751
My issue now is that I need to look up if one given user id is a follower of another given user id. For this I was hoping there was an EndsWith
query I could use so that I could use a point query to increase performance as there will potentially be a lot of 'follower checks' being done. It doesn't appear this is the case.
// request.UserId = "56138dad-e2db-43ac-8ffe-eac4846bf01a";
// request.FollowerUserId = "31d4d0e5-2e48-489f-99fd-ead58a5fd480";
var query = TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equals, request.UserId),
TableOperators.And,
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.???, request.FollowerUserId)
);
I am considering adding a second non-ordered index which contains the RowKey as just the id of the following user for lookups only. Is there a way to achieve what I originally intended, or would it be better (in terms of performance and scalability) to have two indexes for this?
Any help is appreciated.
Upvotes: 1
Views: 379
Reputation: 15613
For storing graph relationships on Azure TableStorage there's a neat Extension called AzureGraphStore and it works wonders.
It basically stores the information duplicated with different pairs of PK/RK so you can easily make queries like: Who is following X? Who does Y follow? Is A following B?
It might solve your problem completely :)
Upvotes: 2