Avoiding exploding indices and recording speed limits in a group of faces using the app

I have an application in which there are Courses, Topics and Tags. Everyone Topiccan be in many Courseand have many Tags. I want to look at everyone Topicthat has a specific Tagx and is in a specific Coursey.

  • Naively, I give each standard a list of Courseids and Tagids, so I can select * from Topic where tagIds = x && courseIds = y. I think this query will require an explosion index: with 30 courses and 30 tags, we look at ~ 900 index entries, right? At 50 x 20, I far exceeded the limit of 5000 people.

  • I could just select * from Topic where tagIds = xand then use the for loop to loop through the result, picking only Topicwhose courseIds.contain(y). This returns more results than I'm interested in, and spends a lot of time deserializing these results, but the index remains small.

  • I could select __KEY__ from Topic where tagIds = xAnd select __KEY__ from Topic where courseIds = yfind the intersection in my application code. If the sets are small, this may be unreasonable.

  • I could create some kind of connection table TopicTagLookupwith field tagIdand courseId. The parent key of these objects will point to the corresponding one Topic. Then I will need to create one of these TopicTagLookupobjects for each combination of courseId x tagId x of the corresponding theme identifier. It really looks like creating my own index. It will still explode, but there will be no limit of 5000 liters. Now, however, I need to write 5000 objects to the same entity group, which will work against the write speed limit in the entity group!

  • . TopicTagQueryCache tagId, courseId a List<TopicId>. select * from TopicTagQueryCache where tagId=x && courseId = y, , getAllById . # 3, x tagId. , .

Appengine , . , . :

, , Topic Course Tag?

+3
3

. - , 3 App Engine . 1 - , App Engine .

4 5 , .

+2

# 5 - () . .

, ( ), Topic ( TopicTagQueryCache, , ).

TopicTagQueryCache, , . , - "" , Topic ( Topic , , , , , - ). ( , , , ).

+1

, , , , , ?

, CourseRef TopicRef, , . "Ref" , . , : Tag\CourseRef...\TopicRef...

Thus, with the tag and the course, you create the Key Tag \ CourseRef and execute the ancestral request , which gives you the set of keys that you can get. This is very fast, because in fact it is direct access, and this should process large lists of courses or topics without list properties.

This method will require you to use the DataStore API to some extent. As you can see, this gives an answer to a specific question, and the model will not be useful for other types of Set operations.

0
source

Source: https://habr.com/ru/post/1795783/


All Articles