Skip to content

Rework list api and use separator in rss redis key#445

Merged
zedeus merged 3 commits into
zedeus:masterfrom
jackyzy823:rework-list
Dec 30, 2021
Merged

Rework list api and use separator in rss redis key#445
zedeus merged 3 commits into
zedeus:masterfrom
jackyzy823:rework-list

Conversation

@jackyzy823
Copy link
Copy Markdown
Contributor

@jackyzy823 jackyzy823 commented Oct 2, 2021

Rework on list related api

List's name( used for display) cannot (and shoud not) be simply converted to slug name (used in URL) by replace " " with "-"

For example:

A display name 推特动物园 of @starknight cannot used as slug name ,it's slug name is 1434331244116938757 (same as list id)
another example
A display name 我的精神病家园 of @cxiaoji can be used as slugname. (maybe it is created in an early time)
A display name VC A-List 's slug name is "vc-a-list"

so we should use /i/lists/<list_id> as primary route and redirect /<screen_name>/lists/<slug_name> to /i/lists/<list_id>(the same as twitter do)

Instead of /<screen_name>/lists/<display_name_or_some_slug_name_converted_from_display_name_by_adding_hyphen>/

UI improvement:

Set html title for List view.

use separator in rss redis key

for example :
previously a rss rediskey might be: rss:abcdef123456 .
So how to distinguish which part is username which part is cursor ? It could be username: abcdef123 cursor:456 or username: abcdef cursor:123456

so we should add separator between this params. I choose / , but i think : is ok too. let me know what should be finally used.

This may resolve #428 related issue.

@jackyzy823 jackyzy823 changed the title Rework list and use separator in rss redis key Rework list api and use separator in rss redis key Oct 2, 2021
Comment thread src/routes/list.nim
let list = await getCachedList(id=(@"id"))
if list.id.len == 0:
resp Http404
await cache(list)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since cache is saved in previous getCachedList , it's not necessary to do it again here.

Copy link
Copy Markdown
Owner

@zedeus zedeus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just some nits and RSS key changes

Comment thread src/routes/list.nim Outdated
Comment on lines +2 to +3
import strutils
import uri
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import strutils
import uri
import strutils, uri

Comment thread src/parser.nim Outdated
members: list{"member_count"}.getInt,
banner: list{"custom_banner_media", "media_info", "url"}.getImageStr
)
if result.banner.len == 0:
Copy link
Copy Markdown
Owner

@zedeus zedeus Dec 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally very much dislike the default banners, this should be removed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, removed.

Comment thread src/routes/rss.nim Outdated
let
cursor = getCursor()
key = $hash(genQueryUrl(query)) & cursor
key = "search/" & $hash(genQueryUrl(query)) & "/" & cursor
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
key = "search/" & $hash(genQueryUrl(query)) & "/" & cursor
key = "search:" & $hash(genQueryUrl(query)) & ":" & cursor

Comment thread src/routes/rss.nim Outdated
cursor = getCursor()
name = @"name"
key = name & cursor
key = "twitter/" & name & "/" & cursor
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
key = "twitter/" & name & "/" & cursor
key = "tweets:" & name & ":" & cursor

Comment thread src/routes/rss.nim Outdated
else: Query(fromUser: @[name])

var key = @"name" & "/" & @"tab"
var key = "tab/" & @"name" & "/" & @"tab" & "/"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, I think it makes sense to put the tab name in front here, so we have e.g. rss:tweets:username, rss:media:username, rss:search:username.

Suggested change
var key = "tab/" & @"name" & "/" & @"tab" & "/"
var key = @"tab" & ":" & @"name" & ":"

Comment thread src/routes/list.nim Outdated
slug = decodeUrl(@"slug")
list = await getCachedList(@"name", slug)
if list.id.len == 0:
resp Http404
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resp Http404
resp Http404, showError("List \"" & @"slug" & "\" not found", cfg)

Comment thread src/routes/list.nim Outdated
template respList*(list, timeline, vnode: typed) =
template respList*(list, timeline, title, vnode: typed) =
if list.id.len == 0:
resp Http404, showError("List \"" & @"list" & "\" not found", cfg)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resp Http404, showError("List \"" & @"list" & "\" not found", cfg)
resp Http404, showError("List \"" & @"id" & "\" not found", cfg)

Comment thread src/redis_cache.nim Outdated
result = await getGraphListById(id)
else:
result = await getGraphList(username, name)
result = await getGraphList(username, slug)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since slug is now only for redirecting, these functions could be renamed to getGraphList and getGraphListBySlug

Comment thread src/redis_cache.nim Outdated
else: await get(toLower("l:" & username & '/' & name))
proc getCachedList*(username=""; slug=""; id=""): Future[List] {.async.} =
let list = if id.len == 0: redisNil
else: await get("l:" & id )
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else: await get("l:" & id )
else: await get("l:" & id)

Comment thread src/parser.nim
name: list{"name"}.getStr,
username: list{"user", "legacy", "screen_name"}.getStr,
userId: list{"user", "legacy", "id_str"}.getStr,
userId: list{"user", "rest_id"}.getStr,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this one? I remember there being some weirdness going on with id_str vs rest_id

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to my observation , there's no id_str under legacy now. so i had to choose rest_id to fill userId.

@zedeus zedeus merged commit 5501752 into zedeus:master Dec 30, 2021
@zedeus
Copy link
Copy Markdown
Owner

zedeus commented Dec 30, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Instances sporadically get a random username's timeline for RSS feeds

2 participants