Comparison

plugins/mod_blocklist.lua @ 12775:1dd468c63a3d

mod_blocklist: Add option 'migrate_legacy_blocking' to disable migration from mod_privacy Tiny performance improvement for new users by skipping this check. Most servers should have gone trough the migration for all active users long ago. As a suitable first step of phasing out this code, we make it possible to disable it first. Later it can be disabled by default, before finally the code is deleted.
author Kim Alvefur <zash@zash.se>
date Mon, 17 Oct 2022 15:20:06 +0200
parent 10111:0f335815244f
child 12977:74b9e05af71e
comparison
equal deleted inserted replaced
12774:fc4adc32a537 12775:1dd468c63a3d
52 cache[username] = blocklist; 52 cache[username] = blocklist;
53 return true; 53 return true;
54 end 54 end
55 55
56 -- Migrates from the old mod_privacy storage 56 -- Migrates from the old mod_privacy storage
57 -- TODO mod_privacy was removed in 0.10.0, this should be phased out
57 local function migrate_privacy_list(username) 58 local function migrate_privacy_list(username)
58 local legacy_data = module:open_store("privacy"):get(username); 59 local legacy_data = module:open_store("privacy"):get(username);
59 if not legacy_data or not legacy_data.lists or not legacy_data.default then return; end 60 if not legacy_data or not legacy_data.lists or not legacy_data.default then return; end
60 local default_list = legacy_data.lists[legacy_data.default]; 61 local default_list = legacy_data.lists[legacy_data.default];
61 if not default_list or not default_list.items then return; end 62 if not default_list or not default_list.items then return; end
73 end 74 end
74 end 75 end
75 end 76 end
76 set_blocklist(username, migrated_data); 77 set_blocklist(username, migrated_data);
77 return migrated_data; 78 return migrated_data;
79 end
80
81 if not module:get_option_boolean("migrate_legacy_blocking", true) then
82 migrate_privacy_list = function (username)
83 module:log("debug", "Migrating from mod_privacy disabled, user '%s' will start with a fresh blocklist", username);
84 return nil;
85 end
78 end 86 end
79 87
80 local function get_blocklist(username) 88 local function get_blocklist(username)
81 local blocklist = cache2:get(username); 89 local blocklist = cache2:get(username);
82 if not blocklist then 90 if not blocklist then