Created
March 24, 2024 12:24
-
-
Save ShadowJonathan/44d1cb7a24ae5e80b67472c86fd42d65 to your computer and use it in GitHub Desktop.
mastodon user federation request prioritisation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map $request_uri $ap_resource_user { | |
~^/@(\w+)$ $1; | |
~^/@(\w+)/\d+$ $1; | |
~^/users/(\w+)$ $1; | |
~^/users/(\w+)/\w+$ $1; | |
~^/users/(\w+)/statuses/\d+$ $1; | |
default ""; | |
} | |
lua_shared_dict your_dict_name 10m; | |
server { | |
# ... | |
set_by_lua_file $lua_prioritized /etc/nginx/lua/user_link_resolve_prio.lua your_dict_name; | |
# ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local ap_likely_user_url = ngx.var.ap_likely_user_url | |
local traffic_class = ngx.var.traffic_class | |
local ap_resource_id = ngx.var.ap_resource_id | |
local ap_resource_user = ngx.var.ap_resource_user | |
if (not (traffic_class == "AP_G" or traffic_class == "AP_F")) | |
or ap_resource_user == "" or ap_resource_user == nil then | |
return nil | |
end | |
local shared_dict = ngx.shared[ngx.arg[1]] | |
local shared_val, _ = shared_dict:get(ap_resource_user) | |
if shared_val then | |
ngx.var.traffic_class = "AP_G" | |
return 1 | |
end | |
if ap_likely_user_url == "1" then | |
shared_dict:set(ap_resource_user, true, 10) | |
ngx.var.traffic_class = "AP_G" | |
return 1 | |
end | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment