Report on office groups without owner - microsoft-graph-api

Use case:
I need to create a report on office groups without owner. This happens when people leave the company and their account is deleted. Their groups live further, but eventually group expiration kicks in and somebody need to take action.
Question: What is the easiest was to create query in graph to filter groups that do not have an owner?
What I currently do is:
List all groups
Enumerate this list and look for groups where the owner array is empty:
https://graph.microsoft.com/v1.0/groups/{id}/owners?$select=mail
This returns an empty array when there are no owners.
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryObjects(mail)",
"value": []
}
This, in theory, works, but takes ages as we have many 10 thousands of groups, so I am looking for a solution that makes this possible with one query. I also tried to filter the exprationDatTime property to limit results but query this doesn't seem to be supported. I mainly need groups that are due to expire.

There is no way how to get groups without owners with one query.
What you can do is to query all groups, expand owners and select only id of the group and id of the owner. It will minimize the response size.
Then iterate through the all groups and check for empty owners collection.
GET https://graph.microsoft.com/v1.0/groups?$expand=owners($select=id)&$select=id

Related

Firestore Map field performance with large dataset

I have a list of products, each user can buy multiple tickets for a product. When I fetch a product I need to know how many tickets a user has bought per product. I currently have product as a separate collection and I fetch a list of tickets per products for the current logged in user. This worked great but I was using an in statement to make a single query to fetch the tickets in a single query for multiple products, and Firestore only allows 10 items in an in statement
I'm considering storing the count of tickets on each product as a map. How does this affect the performance of the snapshotListener? Let's say I listen to 100 products and each has a Map with 100k key-values where the key is a string and the value is an Int.
Is it easy to update the map, can i do an increment on the value of a specific field?
Security is not an issue, it's ok to have the ticket count for all users public
Product {
name: String
....
tickets: {
"USERID": 5,
// 100k more records
}
}
I'm considering storing the count of tickets on each product as a map. How does this affect the performance of the snapshotListener?
It has no effect on the performance of anything other than the time it takes to download the document.
Is it easy to update the map, can i do an increment on the value of a specific field?
Yes, it's easy. Use dot notation to locate the field to increment, and use FieldValue.increment() to increment it.

NoSql Data Modeling with Firebase

Im second guessing how I have modeled my data for a buy/sell app. Each Entity is stored as a node, which contains a list of that entity specified by unique id's.
users -> userId -> [name: "joe", age: 21].
where it gets interesting is the way I store Items. First, I have an items node designed just like the example above. This way I can easily search for any item, or all items. This is handy because I can load all items and add business logic to to display items that can be categorized as Recently Added, Local, Trending etc. These are not nodes in the database.
Now, a user needs access to items they are personally involved with. This kind of item has its own node like so:
selling -> userId -> itemId -> [title: "shoes", size: 11].
Other categories like buying, bought selling, sold liked, archive follow this pattern.
It seems taxing to make changes/searches at so many locations in db when something happens. For instance, if a user wins an item(theres bidding), I have to remove from buying add to bought, add to archive, remove from all items, and for the user who sold the item do the inverse pretty much.
Is it normal to execute this many queries, or should items be more tightly related?
I'm using Firebase by the way. Thanks for your time
Is it normal to execute this many queries, or should items be more tightly related?
Since Firebase doesn't have server-side joins, it is quite common to do joins from the client. This is in itself not always a performance problem, since Firebase pipelines the requests over a single connection.
But it's also quite common to duplicate some of the data to prevent/reduce the number of joins. You'll require a strategy to (or event whether) to keep the duplicated data in sync.
A final alternative is to preload certain data. While that likely doesn't apply here, it can be quite common if the list where you look up from is relatively short, e.g. the list of categories for items.

Neo4j - Searching from an array of nodes

In my situation I've a bunch of nodes that represent the users
and they have relation to books they read.
This user have a property that says where they are from, and I added them to an index, based on their country.
So I would like to search in the index for users from one country, and list the books that people from there read more, some sorting by grouping.
could any one give me a help how to do this?
I'm having some trouble getting users from the index, and doing the query
Couple of assumptions based on your descriptions:
users have a country property, it contains e.g. France as value
you have a index called users and you store the user node's country property there
relationship type to connect users and books is READ
book nodes have a title property
Based on these assumptions the cypher query would look like:
start user=node:users(country='France')
match user-[:READ]->book
return book.title, count(*) as rank
order by rank desc
limit 20
side note: best approach to ask this kind of questions is to create a sample graph on http://console.neo4j.org and share your setup on SO.

Querying Mongodb collection based on parent's attribute

I've got a Posts document that belong to Users, and Users have an :approved attribute. How can I query my Posts using Mongodb s.t. I only get those for where User has :approved => true ?
I could write a loop that creates a new array, but that seems inefficient.
MongoDB does not have any notion of joins.
You've stated in the comments that Posts and Users are separate collections, but your query clearly involves data from both collections, which would imply a join.
I could write a loop that creates a new array, but that seems inefficient.
A join operation in SQL is basically a loop that happens on the server. With no join support on the server side, you'll have to make your own.
Note that many of the libraries (like Morphia) actually have some of this functionality built-in. You are using Mongoid which may have some of this support, but you'll have to do some hunting.
The easiest way to think about it would be to query for unique user ids of users who are approved and then query for post documents where the poster's user_id is in that set.
As Rubish said, you could de-normalize by adding an approved field to the post document. When a user's approval status is toggled (they become approved or unapproved) do an update on the posts collection where, for all of that user's posts, you toggle the denormalized approval field.
Using the denormalized method lets you do one query instead of two (simplifying the logic for the most common case) and isn't too much of a pain to maintain.
Let me know if that makes sense.

Team Foundation Server: Assign work item to a group instead of an individual user

In TFS 2010, is there a way that I can assign a work item to a group (i.e. Developers or Designers) instead of an individual user? I'd also want to be able to create a query so that we can filter on that group as well.
Yes, you can. If your group is a member of the larger group that can be assigned to, then it will appear in the list of assignable users.
For example, a user hierarchy might be like this:
[Assignable Users]
[Developers]
[Project Managers]
Mark Avenius
Joe Schmoe
EDIT
As for the query, you can have the clause Assigned To contains #Me, which I believe will do what you want.

Resources