首页 \ 问答 \ 停止运行应用程序后领域无法正常工作?(Realm not working after stoping running app?)

停止运行应用程序后领域无法正常工作?(Realm not working after stoping running app?)

我通过添加2000条记录来测试Realm。 问题是,当我停止运行应用程序时,即使任何行都没有执行,deleteAllObject方法也不会调用。 我认为beginWriteTransaction方法存在问题。

这是我的代码:

RLMRealm *realm = [RLMRealm defaultRealm];

    [realm beginWriteTransaction];

    [realm deleteAllObjects];

    [realm commitWriteTransaction];

    for (int i = 0 ; i < 2000; i++) {

        [realm beginWriteTransaction];

        PeopleInformation *info = [[PeopleInformation alloc] init];

        info.name = [NSString stringWithFormat:@"%@ %d",@"Rohit",i];
        info.city = @"Delhi";

        [realm addObject:info];
        [realm commitWriteTransaction];

    }

NSLog(@"all object %@", [PeopleInformation allObjects]);

I am testing Realm by adding 2000 records to it. Problem is that when i stopped running application the deleteAllObject method is not calling even any line is not executing. I think problem in beginWriteTransaction method.

This is my code:

RLMRealm *realm = [RLMRealm defaultRealm];

    [realm beginWriteTransaction];

    [realm deleteAllObjects];

    [realm commitWriteTransaction];

    for (int i = 0 ; i < 2000; i++) {

        [realm beginWriteTransaction];

        PeopleInformation *info = [[PeopleInformation alloc] init];

        info.name = [NSString stringWithFormat:@"%@ %d",@"Rohit",i];
        info.city = @"Delhi";

        [realm addObject:info];
        [realm commitWriteTransaction];

    }

NSLog(@"all object %@", [PeopleInformation allObjects]);

原文:https://stackoverflow.com/questions/36565091
更新时间:2023-08-05 22:08

最满意答案

我认为您的结构可能比您最初设计的更简单,并且更贴近您在帖子底部提到的内容。 我还建议您阅读http://blog.getstream.io/best-practices-for-instagram-style-feeds/ ,这听起来与您想要在这里做的相似。

有关Feed类型的简化细分:

  • 通知Feed适用于内容创作者(“15个人喜欢你的帖子”)。
  • 聚合Feed适用于粉丝(“添加了12个帖子”)。
  • 平面Feed是添加核心活动(在您的案例中为“实体”)的好地方,但您也可以使用活动模型上的“收件人”字段将这些活动的其他副本保存到其他聚合和通知订阅源,类似于CC发电子邮件

任何Feed类型都可以遵循Flat Feed,但我们通常建议只有平面Feed和聚合Feed会跟随其他平面Feed。 通知源通常是独立的,我将在下面描述。

让我们做出以下假设:

  • 有一个名为“Silverthorne”的管理员用户,ID为12
  • 组织机构ID 56是“Acme Inc”
  • Ian是ID为74的普通用户
  • Silverthorne准备一些实体内容,当保存到您自己的数据库时,其ID为63

让我们创建一个名为org的平面Feed,其中将进行实体活动,并为聚合数据创建名为org_aggregated的聚合Feed,称为notifications Feed,称为timeline用户平面Feed。 如果您的用户可以看到其他用户(而不是组织)创作的所有内容的Feed,那么我建议使用另一个名为usercontent平面Feed。

对于Silverthorne将此​​活动发布到GetStream,活动actor将是"user:12" ,动词可以是"post" ,对象将是"entity:63"

为了解决这个问题,因为我不知道你正在使用哪个SDK,它将是:

# acme inc gets created as an organization, and so its aggregated feed
# should follow the org's flat feed
acme_org_feed = getstreamClient->feed('org', '56')
acme_org_agg_feed = getstreamClient->feed('org_aggregated', '56')
acme_org_agg_feed->follow(acme_org_feed)

此时,添加到Acme的org flat feed的每个实体也将被聚合。 您可以设置如何在GetStream仪表板上汇总这些内容。

现在,我们让Ian关注Acme:

# ian is a member of Acme Inc, so follow their entity feed
ian_feed = getstreamClient->feed('timeline', '74')
ian_feed->follow(acme_org_feed)

如果Ian是新注册,您可以向Acme的通知Feed发送活动,如下所示:

acme_notif_feed = getstreamClient->feed('org_notification', '56')
acme_notif_feed->addActivity({
  'actor': 'user:74',
  'verb': 'registration',
  'object': 'user:74'
})

稍后检索此通知Feed时,它会将所有谓词组合在一起,然后细分通知活动,以便您可以选择以不同方式报告这些通知。

现在让我们让Silverthorne将实体添加到GetStream:#Silverthorne为Acme Inc的实体Feed添加了一项活动#我们将“cc”活动添加到聚合Feed acme_org_feed-> addActivity({'actor':'user:12','动词':'post','object':'entity:63','to':['usercontent:12'],...要跟踪的任何其他元数据})

保存时,GetStream会执行以下操作:

  • 它将活动存储在Acme的org平面饲料中( org:56
  • 它将副本保存到Ian的时间线中,因为user:74跟随org:56的平面馈送org:56
  • 它还从'To'字段中将副本保存到Silverthorne的feed( usercontent:12 ); 这完全是可选的
  • 它将副本保存到Acme的聚合Feed中( org_aggregated:56 ),因为聚合的Feed跟随平面Feed

当Ian登录时,您的应用程序现在有几个可能的供稿和选项显示,这完全取决于您的应用:

  • 如果Ian应该看到他所遵循的所有内容的时间表,你将获取timeline:74 feed,它将有一个实体#63的副本
  • 如果Ian应该看到他所遵循的所有组织的列表,您可以获取ian_feed->followed()以获取Ian所遵循的每个Feed的列表
  • 对于Ian所遵循的每个提要,您可以获取该组织的聚合提要以查看摘要(即,获取org_aggregated:56和Ian可以看到one new entity added in the past day如果这是您聚合内容的方式)

这里的关键是Ian不必关注Feed以查看内容,您的应用可以将任何Feed提取给任何用户。

如果Ian要“分享”或“喜欢”Silverthorne发布的实体,您可以在'org_notification:56'Feed中添加一个新活动,其中'user:74'作为Actor,'entity:63'是对象,动词是你想要的任何字符串(最多20个字符)。 如果您希望您的应用看到其他用户如何与组织的帖子互动,您可以获取org_notification:56并且所有用户都可以看到“Ian org_notification:56 entity 63”,或者您的UI需要提供该信息。

希望有助于澄清事情并为您提供一些额外的细节。 如果您需要进一步的帮助或想法,请通过电子邮件联系我们的支

作为最后一点,我不认为我会做$userId-$orgId ...我们的一些SDK(即Rails和Django)将自动尝试“丰富”数据库中的那些值,所以你要需要额外的逻辑来尝试稍后拆分这些值。 我们建议使用UUID作为无冲突标识符,但这完全取决于您控制。 如果用户真的可以成为多个组织的一部分,那么您可以让该用户“关注”该组织的Feed。


I think your structure could be simpler than you initially designed, and be closer to what you mention at the bottom of your post. I'd also recommend you have a read through http://blog.getstream.io/best-practices-for-instagram-style-feeds/ which sounds similar to what you're wanting to do here.

For a simplified breakdown of our feed types:

  • Notification feeds are meant for the creators of content ("15 people liked your post").
  • Aggregated feeds are meant for followers ("12 posts were added").
  • Flat feeds would be great places to add the core activities ("entities" in your case?), but you can also save additional copies of those activities to other aggregated and notification feeds using the "To" field on the activity model, similar to CC'ing an email

Any feed type can follow a Flat feed, but we generally recommend that only flat feeds and aggregated feeds follow other flat feeds. Notification feeds generally stand alone, which I'll describe below.

Let's make the following assumptions:

  • There's an admin user named "Silverthorne" with an id of 12
  • Organization ID 56 is "Acme Inc"
  • Ian is a regular user with an ID of 74
  • Silverthorne prepares some Entity content that, when saved to your own database has an ID of 63

Let's create a flat feed called org where entity activities will be made, and aggregated feed called org_aggregated for aggregated data, a notification feed called notifications, a flat feed for users called timeline. If your users could see a feed of everything authored by another user (not by organization) then I'd recommend another flat feed called usercontent.

For Silverthorne to post this activity to GetStream, the activity actor would be "user:12", the verb could be "post", the object would be "entity:63"

To pseduocode this, since I don't know which SDK you're using, would be something like:

# acme inc gets created as an organization, and so its aggregated feed
# should follow the org's flat feed
acme_org_feed = getstreamClient->feed('org', '56')
acme_org_agg_feed = getstreamClient->feed('org_aggregated', '56')
acme_org_agg_feed->follow(acme_org_feed)

At this point, every entity that gets added to Acme's org flat feed will also get aggregated. You can set how these get rolled up on your GetStream dashboard.

Now, let's have Ian follow Acme:

# ian is a member of Acme Inc, so follow their entity feed
ian_feed = getstreamClient->feed('timeline', '74')
ian_feed->follow(acme_org_feed)

If Ian is a new registration, you could send an activity to Acme's notification feed like this:

acme_notif_feed = getstreamClient->feed('org_notification', '56')
acme_notif_feed->addActivity({
  'actor': 'user:74',
  'verb': 'registration',
  'object': 'user:74'
})

When you retrieve this notification feed later, it will group all verbs together, and then break down the notification activities, so your UI could report those differently if you choose.

Now let's have Silverthorne add that Entity to GetStream: # Silverthorne adds an activity to Acme Inc's entity feed # we'll "cc" the activity to the aggregated feed acme_org_feed->addActivity({ 'actor': 'user:12', 'verb': 'post', 'object': 'entity:63', 'to': ['usercontent:12'], ... any other metadata you want to track })

When this is saved, here's what GetStream would do:

  • it stores the activity in the org flat feed for Acme (org:56)
  • it saves a copy into Ian's timeline, since user:74 follows the flat feed for org:56
  • it also saves a copy to Silverthorne's feed (usercontent:12) from the 'To' field; this is entirely optional
  • it saves a copy into the aggregated feed for Acme (org_aggregated:56) since the aggregated feed follows the flat feed

When Ian logs in, your app now has several possible feeds and options to show, and this is entirely up to your app:

  • if Ian should see a timeline of everything he follows, you'd fetch the timeline:74 feed, which will have a copy of Entity #63
  • if Ian should see a list of all organizations he follows, you can fetch ian_feed->followed() to get a list of every feed that Ian follows
  • for each of those feeds Ian follows, you could fetch that org's aggregated feed for Ian to see a summary (ie, fetch org_aggregated:56 and Ian could see one new entity added in the past day if that's how you aggregate your content)

The key here is that Ian doesn't have to follow a feed in order to see the content, your app can pull any feed to display to any user.

If Ian were to 'share' or 'like' that entity that Silverthorne posted, you'd add a new activity to the 'org_notification:56' feed with 'user:74' as the Actor, 'entity:63' is the object, and verb is whatever string you want (up to 20 characters). If you want your app to see how other users interact with the org's posts, you could fetch org_notification:56 and all users could see "Ian liked entity 63", or however your UI needs to present that.

Hope that helps to clarify things and give you some additional details. Contact our support team via email if you want further help or ideas.

As a final note, I don't think I'd do $userId-$orgId ... some of our SDKs (ie, Rails and Django) will automatically try to 'enrich' those values in your database, so you'd need additional logic to attempt to split apart those values later. We recommend using a UUID for a collision-free identifier, but that's entirely up to you to control. If a user can really be part of multiple organizations, you can just have that user 'follow' the organization's feed.

相关问答

更多
  • 没有简单的方法将您的Feed限制为500个项目。 有两种方法可以从Stream中移除活动: removeActivity方法,该方法通过foreign_id或activity id( https://getstream.io/docs/js/#removing-activities )一次删除1个活动 应用程序仪表板上的“截断数据”按钮,该按钮将删除流中的所有活动。 通过跟踪您添加到Stream中的所有活动,然后定期挑选能够让您超过500个的活动,可能会获得您要查找的行为。 希望这有助于! There's ...
  • 我们建议使用后端系统与Stream通信。 将逻辑放在前端系统(或React native)意味着您将API凭据存储在面向公众的应用程序或移动应用程序中,这很容易进行逆向工程。 We recommend using a back-end system to communicate with Stream. Putting logic in the front-end system (or React native) means you'd be storing your API credentials in ...
  • “到”字段包含在“活动”中,当它们最初添加到的供稿被检索时。 但是,当检索包含通过'到'字段定位到达的活动的订阅源时,该活动不会包含'至'字段。 The 'to' field is included on Activities when the feed they were originally added to is retrieved. However when a feed is retrieved that contains an Activity that arrived there via 't ...
  • 为了保证安全,您首先要在服务器端获取Feed令牌。 在服务器端初始化Stream客户端时,您将传递应用程序密钥,以便访问所有应用程序的源。 然后,令牌可以传递到您的客户端应用程序(单页面应用程序,移动应用程序等)。 服务器端代码示例: var stream = require('getstream'); // pass the app secret when connecting on the server-side streamclient = stream.connect('', '
  • 这一点都不奇怪 - 你只是误用了溪流。 您假设对Read的单个调用将读取您要求的整个缓冲区。 事实并非如此 - 它可以轻松地减少回报。 你应该改变这一点: responseStream.Read(buffer, 0, buffer.Length); file.Write(buffer, 0, buffer.Length); byteReaded += bytesCountToRead; 至: int chunkRead = responseStream.Read(buffer, 0, buffer.Len ...
  • 您需要使lambda异步并等待对CrossMedia.Current.PickPhotoAsync的异步调用: addphotos.Clicked = new Command(async () => { if (CrossMedia.Current.IsPickPhotoSupported) { if (!CrossMedia.Current.IsPickPhotoSupported) { DisplayAlert("Photos N ...
  • 我认为您的结构可能比您最初设计的更简单,并且更贴近您在帖子底部提到的内容。 我还建议您阅读http://blog.getstream.io/best-practices-for-instagram-style-feeds/ ,这听起来与您想要在这里做的相似。 有关Feed类型的简化细分: 通知Feed适用于内容创作者(“15个人喜欢你的帖子”)。 聚合Feed适用于粉丝(“添加了12个帖子”)。 平面Feed是添加核心活动(在您的案例中为“实体”)的好地方,但您也可以使用活动模型上的“收件人”字段将这些活动 ...
  • 您无法在Getstream.io API上存储图像或视频等资源,而应存储对位于您自己的存储或第三方视频/图像托管服务中的资源的引用。 使用活动的object字段或自定义字段来存储引用,阅读有关文档中活动允许的字段的更多信息。 从Getstream.io API检索活动时,您负责检索对象字段中引用的实际视频/对象。 You can not store resources like images or videos on the Getstream.io API, instead you should stor ...
  • 通过to字段添加到Feed的活动也会发送给其关注者,这样您就可以创建更复杂的流程,就像您描述的那样。 例如:说饲料news:tommaso遵循feed tag:programming 。 当您向Feed news:hackernews添加活动时news:hackernews并在“to”目标列表中添加tag:programming , news:tommaso也将在其Feed中接收活动。 Activities added to a feed via the to field, are also sent to ...
  • 您似乎缺少此处概述的一些设置步骤: https : //github.com/GetStream/Stream-Laravel (Stream-Laravel包) 特别是针对您的错误消息,您的应用似乎没有配置FeedManager外观。 It seems like you are missing some of the setup steps outlined here: https://github.com/GetStream/Stream-Laravel (the Stream-Laravel pack ...

相关文章

更多

最新问答

更多
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)
  • 是否可以嵌套hazelcast IMaps?(Is it possible to nest hazelcast IMaps? And whick side effects can I expect? Is it a good Idea anyway?)
  • UIViewAnimationOptionRepeat在两个动画之间暂停(UIViewAnimationOptionRepeat pausing in between two animations)
  • 在x-kendo-template中使用Razor查询(Using Razor query within x-kendo-template)
  • 在BeautifulSoup中替换文本而不转义(Replace text without escaping in BeautifulSoup)
  • 如何在存根或模拟不存在的方法时配置Rspec以引发错误?(How can I configure Rspec to raise error when stubbing or mocking non-existing methods?)
  • asp用javascript(asp with javascript)
  • “%()s”在sql查询中的含义是什么?(What does “%()s” means in sql query?)
  • 如何为其编辑的内容提供自定义UITableViewCell上下文?(How to give a custom UITableViewCell context of what it is editing?)
  • c ++十进制到二进制,然后使用操作,然后回到十进制(c++ Decimal to binary, then use operation, then back to decimal)
  • 以编程方式创建视频?(Create videos programmatically?)
  • 无法在BeautifulSoup中正确解析数据(Unable to parse data correctly in BeautifulSoup)
  • webform和mvc的区别 知乎
  • 如何使用wadl2java生成REST服务模板,其中POST / PUT方法具有参数?(How do you generate REST service template with wadl2java where POST/PUT methods have parameters?)
  • 我无法理解我的travis构建有什么问题(I am having trouble understanding what is wrong with my travis build)
  • iOS9 Scope Bar出现在Search Bar后面或旁边(iOS9 Scope Bar appears either behind or beside Search Bar)
  • 为什么开机慢上面还显示;Inetrnet,Explorer
  • 有关调用远程WCF服务的超时问题(Timeout Question about Invoking a Remote WCF Service)