commit 9a0a03d
default
·
2022-11-27 08:45:06 +0000 UTC
parent 832bbfd
New function object_del_if_unref().
M
data.c
+16,
-2
1@@ -552,6 +552,20 @@ int object_del(const char *id)
2 }
3
4
5+int object_del_if_unref(const char *id)
6+/* deletes an object if its n_links < 2 */
7+{
8+ xs *fn = _object_fn(id);
9+ int n_links;
10+ int ret = 0;
11+
12+ if (mtime_nl(fn, &n_links) > 0.0 && n_links < 2)
13+ ret = object_del(id);
14+
15+ return ret;
16+}
17+
18+
19 d_char *object_children(const char *id)
20 /* returns the list of an object's children */
21 {
22@@ -791,8 +805,8 @@ int timeline_del(snac *snac, char *id)
23 object_user_cache_del(snac, id, "public");
24 object_user_cache_del(snac, id, "private");
25
26- /* NOTE: this is a good place to count the # of links
27- of the object and object_del() it if it's < 2 */
28+ /* try to delete the object if it's not used elsewhere */
29+ object_del_if_unref(id);
30
31 return ret;
32 }
M
snac.h
+1,
-0
1@@ -60,6 +60,7 @@ d_char *index_list(const char *fn, int max);
2 d_char *index_list_desc(const char *fn, int max);
3
4 int object_del(const char *id);
5+int object_del_if_unref(const char *id);
6
7 int follower_add(snac *snac, char *actor, char *msg);
8 int follower_del(snac *snac, char *actor);