Get single activity by id - getstream-io

How to get an activity by its id (unique uuid) or by foreign_id + time?
I could not find it in documentation. All information there represents how to get feed in pages. Not a single activity.

If you save the id you get from adding an activity, then you can opt to fetch activities based on the id, using "id_gte" or "id_lte" and only fetch with offset 0 and limit 1. Such as:
$feed->getActivities(0, 1, ['id_gte' => $id]);
This code is based on php, but their sdk should have equal functions for other languages if you require.

The general goal should be to use Stream as a secondary data store. Your proprietary data from your customers should always be accessible in your own primary data store: most likely a RDBMS like PostgreSQL. When new follow relationships get created, or new activities get added, you should store them locally, and replicate the data to GetStream. Then access feeds when a users wants to see a timeline or notification feed, and complement your data from data found in your own DB (for example: comments, likes, author information, ...)
For this reason, there is no getActivity(uuid) method available.

Using the python client you can get an activity by its ID
import stream
client = stream.connect('YOUR_API_KEY', 'API_KEY_SECRET')
client.get_activities(ids=[activity_id])
Or by its foreign_id + time
client.get_activities(foreign_id_times=[
(foreign_id, activity_time),
])
Taken from https://github.com/GetStream/stream-python/blob/main/README.md

Related

How to insert item in CosmosDB(SQL API) from using Azure Data Factory activity

I have an ADF pipeline which is iterating over a set of files, performing various operations and I have an Azure CosmosDB (SQL API) instance where I would like to insert the name of file and a timestamp, mainly to keep track on which files have been already processed and which not, but in the future I might want to add some other bits of data related to each file.
What I have is my CosmosDB
And currently I am trying to utilice the Copy Data Activity for the insert part.
One problem that I have is that this particular activity expects source while at this point I have only the filename. In theory it was an option to use the Blob Storage from where I read the file at the beginning, but since the Blob Storage is set to store binary files I got the following error if I try to use it as source
Because of that I created a dummy CosmosDB Linked service, but I have several issues with this approach:
Generally the idea for dummy source is not very appealing to me
I haven't find a lot of information on the topic but it seems that if I want to use something in the Sink I need to SELECT from the source
Even though I have selected a value for the id the item is not saved with the selected value from the Source query, but as you can see from the first screenshot I got a GUID and only the name is as I want it.
So my questions are two. I just learn ADF but this approach doesn't look like the proper way to insert item into CosmosDB from activity, so a better/more common approach would be appreciated. If there is not better proposal, how can I at least apply my own value for the id column? If I create the item in the CosmosDB GUI and save it from there, as you can see I am able to use the filename as id which for now seems like a good idea to me, but I wasn't able to add custom value (string or int) when I was trying through the activity, so how can I achieve this?
This is how my Sink looks like

How to specify feed when using 'updateActivities' with Stream?

The updateActivities method in the Stream API is perplexing, as the docs seem to indicate that a feed is not specified during this operation. How is this supposed to work?
The other activity methods (addActivity, removeActivity) are performed on a feed object, which makes sense. But the docs show updateActivities as a method on the client object, with no way to specify the feed containing the activity.
From the docs:
var now = new Date();
activity = {
"actor": "1",
"verb":"like",
"object": "3",
"time": now.toISOString(),
"foreign_id": "like:3",
"popularity": 100
};
// first time the activity is added
user1.addActivity(activity);
// update the popularity value for the activity
activity.popularity = 10;
// send the update to the APIs
client.updateActivities([activity]);
My expectation (and the only thing that makes sense, as far as I can tell), would be that the updateActivities method would be on the feed object, since a foreign_id is not unique across all feeds.
(Previous assumption based on lots of experience using identical foreign IDs across multiple feeds.)
When an activity is added to a feed, Stream generates a unique ID for it and uses such ID to propagate the activity to the direct feed and if any, to all follower feeds. In fact only references to activities are stored inside feeds.
Stream also guarantees that IDs are consistent for same time and foreign_id values. This means that if you add an activity with same time and foreign_id, it will always end up with the same ID.
This allows you to control activity uniqueness and to update all occurrences of an activity without keeping track of all feeds that can have a copy (the to target and follow relationships would make this a very complex task!).

BigQuery - How to paginate over result

I have the following problem:
We have a table (partitioned by timestamp) that saves data from IoT devices (a lot of data, the expected ratio for new incoming data is about every 30sec each device).
The problem is that we will serving a query service and users can set a "since" and "until" filters over a "ts" field (the timestamp), but I want to paginate the results by 10,20,... (wherever the user sets "pageSize").
How I can do this? since saving the whole result in a temp table (and using Tabledata.list API) is not an option 'cause I would have a temp table for each different request (different in terms of filters...)
Thanks in advance!!!
For Nodejs the library automatically paginates using the token from previous request for you as described here https://cloud.google.com/bigquery/docs/paging-results#bigquery-paging-nodejs
on the other hand you have some options for manual pagination if you read the implementation code here: https://github.com/googleapis/nodejs-bigquery/blob/master/src/index.ts

How table storage loops works?

Does anyone knows how data is beeing retrived from table storage?
var result = ctx.CreateQuery<Contact>("Contacts")
.Where(x => x.PartitionKey == "key")
.Take(50)
.AsTableServiceQuery<Contact>().Execute();
foreach(var item in result)
{
Console.WriteLine(item.FirstName);
}
Does it get all items from storage and than loops through them or it get each item separately?
Take a look at the following links.
This one talks about the basics of table storage -
http://msdn.microsoft.com/en-us/magazine/ff796231.aspx
This one covers more than you are asking about, but there are some How To code examples that might be useful for querying table storage - http://www.windowsazure.com/en-us/develop/net/how-to-guides/table-services/
I also recommend this video from the PDC. It's a deep dive into tables and queues in Azure. - http://www.microsoftpdc.com/2009/svc09
You could have checked this using Fiddler. Table service is a REST Service, the CreateQuery() method creates REST Query, executes a HTTP REST Call, then parses the result, which is a XML containing all the entities in the result for the query (limit to 1000 and including continuation tokens if result is more than 1000). All the items are in the result XML, there is no point for querieng every single item from the result.

CouchDB - Auto-increment

In a non-replicate scenario (or one where we have one write master only), would the following work as quick way to give a doc an auto-increment id to small internal customer datbase.
On inserting a new customer query http://couhdb/mydb to get the metadata
Then add doc_count + doc_deleted_count = autoIncId
Set a property on the doc as .oldDbCompatIdThatClientIsUsedTo = auotIncId
This would mean serialize/sync the process of getting the db metadata and writting the doc but thats not a problem given 20 customers added a day etc..
I can think of a couple of ways of doing this:
Create a view that returns max(id) and just assign max(id) + 1 to the new item (there's some chance of collision here though)
Store another document in the database that isn't a normal record but just contains the sequence value. When you want to do a new insert fetch the current value from this doc, add one, save it back to the doc and then if none of that failed use that id for the new record

Resources