mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-12 18:56:12 +00:00
parent
e413350be3
commit
bcd187cf08
|
@ -71,9 +71,7 @@ impl RateLimited {
|
||||||
{
|
{
|
||||||
// Does not need to be blocking because the RwLock in settings never held across await points,
|
// Does not need to be blocking because the RwLock in settings never held across await points,
|
||||||
// and the operation here locks only long enough to clone
|
// and the operation here locks only long enough to clone
|
||||||
let rate_limit: RateLimitConfig = Settings::get()
|
let rate_limit: RateLimitConfig = Settings::get().rate_limit.unwrap_or_default();
|
||||||
.rate_limit
|
|
||||||
.unwrap_or_else(RateLimitConfig::default);
|
|
||||||
|
|
||||||
// before
|
// before
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,10 +13,12 @@ pub fn setup(pool: DbPool) {
|
||||||
|
|
||||||
let conn = pool.get().unwrap();
|
let conn = pool.get().unwrap();
|
||||||
active_counts(&conn);
|
active_counts(&conn);
|
||||||
reindex_aggregates_tables(&conn);
|
|
||||||
|
// On startup, reindex the tables non-concurrently
|
||||||
|
reindex_aggregates_tables(&conn, false);
|
||||||
scheduler.every(1.hour()).run(move || {
|
scheduler.every(1.hour()).run(move || {
|
||||||
active_counts(&conn);
|
active_counts(&conn);
|
||||||
reindex_aggregates_tables(&conn);
|
reindex_aggregates_tables(&conn, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
let conn = pool.get().unwrap();
|
let conn = pool.get().unwrap();
|
||||||
|
@ -35,19 +37,20 @@ pub fn setup(pool: DbPool) {
|
||||||
/// Reindex the aggregates tables every one hour
|
/// Reindex the aggregates tables every one hour
|
||||||
/// This is necessary because hot_rank is actually a mutable function:
|
/// This is necessary because hot_rank is actually a mutable function:
|
||||||
/// https://dba.stackexchange.com/questions/284052/how-to-create-an-index-based-on-a-time-based-function-in-postgres?noredirect=1#comment555727_284052
|
/// https://dba.stackexchange.com/questions/284052/how-to-create-an-index-based-on-a-time-based-function-in-postgres?noredirect=1#comment555727_284052
|
||||||
fn reindex_aggregates_tables(conn: &PgConnection) {
|
fn reindex_aggregates_tables(conn: &PgConnection, concurrently: bool) {
|
||||||
for table_name in &[
|
for table_name in &[
|
||||||
"post_aggregates",
|
"post_aggregates",
|
||||||
"comment_aggregates",
|
"comment_aggregates",
|
||||||
"community_aggregates",
|
"community_aggregates",
|
||||||
] {
|
] {
|
||||||
reindex_table(conn, table_name);
|
reindex_table(conn, table_name, concurrently);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reindex_table(conn: &PgConnection, table_name: &str) {
|
fn reindex_table(conn: &PgConnection, table_name: &str, concurrently: bool) {
|
||||||
info!("Reindexing table {} ...", table_name);
|
let concurrently_str = if concurrently { "concurrently" } else { "" };
|
||||||
let query = format!("reindex table concurrently {}", table_name);
|
info!("Reindexing table {} {} ...", concurrently_str, table_name);
|
||||||
|
let query = format!("reindex table {} {}", concurrently_str, table_name);
|
||||||
sql_query(query).execute(conn).expect("reindex table");
|
sql_query(query).execute(conn).expect("reindex table");
|
||||||
info!("Done.");
|
info!("Done.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue