summaryrefslogtreecommitdiff
path: root/src/portal
diff options
context:
space:
mode:
Diffstat (limited to 'src/portal')
-rw-r--r--src/portal/py/modules/patreon.py17
-rw-r--r--src/portal/src/post_cache.c27
-rw-r--r--src/portal/src/search.c7
3 files changed, 31 insertions, 20 deletions
diff --git a/src/portal/py/modules/patreon.py b/src/portal/py/modules/patreon.py
index 8ef9ad1..9f672c1 100644
--- a/src/portal/py/modules/patreon.py
+++ b/src/portal/py/modules/patreon.py
@@ -75,7 +75,6 @@ class PatreonUser(PatreonBase):
# image_file: https://www.patreon.com/posts/emma-again-29391136
# text_only: https://www.patreon.com/posts/hello-update-29391184
# tags
- # Query doesn't complete.
def create_post(self, data: ParsedJson, hash: str) -> Optional[Post]:
#if 'access_rules' in data['relationships']:
@@ -99,7 +98,8 @@ class PatreonUser(PatreonBase):
kwargs['author'] = self.user
kwargs['title'] = data['attributes']['title']
kwargs['likes'] = data['attributes']['like_count']
- kwargs['comments'] = data['attributes']['comment_count']
+ if 'comment_count' in data['attributes']:
+ kwargs['comments'] = data['attributes']['comment_count']
kwargs['text'] = ''
if 'content' in data['attributes']:
kwargs['text'] = data['attributes']['content']
@@ -107,10 +107,12 @@ class PatreonUser(PatreonBase):
media = {}
if data['relationships']['media']['data']:
for m in data['relationships']['media']['data']:
- media[m['id']] = self.attachments[m['id']]
+ if m['id'] in self.attachments:
+ media[m['id']] = self.attachments[m['id']]
if 'attachments' in data['relationships'] and data['relationships']['attachments']['data']:
for a in data['relationships']['attachments']['data']:
- media[a['id']] = self.attachments[a['id']]
+ if a['id'] in self.attachments:
+ media[a['id']] = self.attachments[a['id']]
kwargs['media'] = media
post = Post(**kwargs)
self.module.add_to_map(unique_id, post)
@@ -160,6 +162,7 @@ class PatreonUser(PatreonBase):
hash = self.module.add_raw_response(obj)
try:
+ # Cursor should be 'null' at the end of pagination.
self.cursor = obj['meta']['pagination']['cursors']['next']
except KeyError:
self.cursor = None
@@ -170,7 +173,7 @@ class PatreonUser(PatreonBase):
elif inc['type'] == 'media':
if 'download_url' in inc['attributes']:
media_url = inc['attributes']['download_url']
- elif inc['attributes']['image_urls']:
+ elif inc['attributes'].get('image_urls', None):
media_url = inc['attributes']['image_urls']['original']
elif 'default_thumbnail' in inc['attributes']['display']:
media_url = inc['attributes']['display']['default_thumbnail']['url']
@@ -201,6 +204,10 @@ class PatreonUser(PatreonBase):
if index == num:
request_satisfied = True
+ if not self.cursor:
+ self.completed = True
+ break
+
return request_satisfied
class PatreonModule(Module):
diff --git a/src/portal/src/post_cache.c b/src/portal/src/post_cache.c
index d6b885b..964ca63 100644
--- a/src/portal/src/post_cache.c
+++ b/src/portal/src/post_cache.c
@@ -1,3 +1,6 @@
+#define AL_LOG_SECTION "post_cache"
+#include <al/log.h>
+
#include "post_cache.h"
void camu_post_cache_init(struct camu_post_cache *cache)
@@ -7,17 +10,20 @@ void camu_post_cache_init(struct camu_post_cache *cache)
void camu_post_cache_push(struct camu_post_cache *cache, struct camu_post *post, bool clone)
{
- struct camu_post *check = camu_post_cache_get(cache, &post->unique_id);
- if (!check) {
- if (clone) {
- struct camu_post *cloned = al_alloc_object(struct camu_post);
- camu_post_clone(cloned, post);
- post = cloned;
+ struct camu_post *check;
+ al_array_foreach(cache->cache, i, check) {
+ if (al_str_eq(&check->unique_id, &post->unique_id)) {
+ log_info("Replacing post %.*s in the cache.", al_str_x(&post->unique_id));
+ camu_post_free(check);
+ al_array_remove_at(cache->cache, i);
}
- al_array_push(cache->cache, post);
- } else if (!clone) {
- camu_post_free(post);
}
+ if (clone) {
+ struct camu_post *cloned = al_alloc_object(struct camu_post);
+ camu_post_clone(cloned, post);
+ post = cloned;
+ }
+ al_array_push(cache->cache, post);
}
struct camu_post *camu_post_cache_get(struct camu_post_cache *cache, str *unique_id)
@@ -27,9 +33,6 @@ struct camu_post *camu_post_cache_get(struct camu_post_cache *cache, str *unique
if (al_str_eq(&post->unique_id, unique_id)) {
return post;
}
- if (al_str_eq(&post->author.unique_id, unique_id)) {
- return post;
- }
}
return NULL;
}
diff --git a/src/portal/src/search.c b/src/portal/src/search.c
index 3f012bf..d442d94 100644
--- a/src/portal/src/search.c
+++ b/src/portal/src/search.c
@@ -20,7 +20,7 @@ bool camu_python_init(void)
PyStatus status = Py_PreInitialize(&pre_config);
if (PyStatus_Exception(status)) {
- log_error("Preinitialization failed.");
+ log_error("Pre-initialization failed.");
return false;
}
@@ -98,7 +98,7 @@ static nn_thread_result NNWT_THREADCALL queue_thread(void *userdata)
al_array_init(search->pages);
search->bridge = bridge;
al_array_push(bridge->searches, search);
- log_info("New search %x (%.*s).", result.id, al_str_x(&cmd->query));
+ log_info("New search %.*s(%x).", al_str_x(&cmd->query), result.id);
} else {
log_info("Failed to create search (%.*s).", al_str_x(&cmd->query));
}
@@ -114,7 +114,7 @@ static nn_thread_result NNWT_THREADCALL queue_thread(void *userdata)
al_array_foreach_ptr(search->pages, j, page) {
if (page->num == cmd->num) break;
}
- log_info("Loading page %i (%.*s).", cmd->num, al_str_x(&search->query));
+ log_info("Loading page %i (%.*s(%x)).", cmd->num, al_str_x(&search->query), cmd->id);
if (portal_bridge_get_page(search, search->id, cmd->num) == -1) {
break;
}
@@ -173,6 +173,7 @@ static void results_signal_callback(void *userdata)
}
}
+// @TODO: Fully defer init.
void camu_portal_init(struct camu_portal_bridge *bridge, struct camu_post_cache *cache,
struct nn_event_loop *loop, void *userdata)
{