Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Instances] Add expire_at Column #4820

Merged
merged 4 commits into from
Mar 30, 2025
Merged

Conversation

Akkadius
Copy link
Member

@Akkadius Akkadius commented Mar 30, 2025

Description

  • New Column This adds an expire_at column to instance_list table so that we have a finite value to index on. Currently, queries perform full table scans during instance pruning and creates table contention.
  • PurgeExpiredInstances Instead of offsetting purged instances 1 day after expiration, we now offset by 1 hour to purge instances faster. This is configurable by rule Instances:ExpireOffsetTimeSeconds

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Testing

Migration testing

 World |    Info    | UpdateManifest ---------------------------------------------------------------------- 
 World |    Info    | UpdateManifest Running database migrations. Please wait... 
 World |    Info    | UpdateManifest ---------------------------------------------------------------------- 
 World |    Info    | UpdateManifest [9321] [2025_03_30_instance_list_add_expire_at.sql] [ok] 
 World |    Info    | UpdateManifest ---------------------------------------------------------------------- 
 World |    Info    | CheckDbUpdates Updates ran successfully, setting database version to [9321] from [9320] 

Created 1 minute expiration instance

sub EVENT_SAY {
    if ($text=~/instance/i) {
        my $instance_id = quest::CreateInstance("halas", 0, 60);
        $client->AssignToInstance($instance_id);
        $client->MoveZoneInstance($instance_id);
    }
}

Instance expiring

 World |    Info    | operator() Purging expired instances 
 World |   Query    | QueryDatabase SELECT id, zone, version, is_global, start_time, duration, expire_at, never_expires, notes FROM instance_list WHERE expire_at <= (UNIX_TIMESTAMP()) AND never_expires = 0 -- (1 row returned) (0.000220s)
 World |   Query    | QueryDatabase DELETE FROM instance_list WHERE id IN (101) -- (1 row affected) (0.010887s)
 World |   Query    | QueryDatabase DELETE FROM instance_list_player WHERE id IN (101) -- (1 row affected) (0.001782s)
 World |   Query    | QueryDatabase DELETE FROM respawn_times WHERE instance_id IN (101) -- (0 rows affected) (0.000073s)
 World |   Query    | QueryDatabase DELETE FROM spawn_condition_values WHERE instance_id IN (101) -- (0 rows affected) (0.000033s)
 World |   Query    | QueryDatabase UPDATE `character_corpses` SET is_buried = 1, instance_id = 0 WHERE instance_id IN (101) -- (0 rows affected) (0.000047s)
 World |   Query    | QueryDatabase DELETE dynamic_zone_members FROM dynamic_zone_members INNER JOIN dynamic_zones ON dynamic_zone_members.dynamic_zone_id = dynamic_zones.id WHERE dynamic_zones.instance_id IN (101) -- (0 rows affected) (0.000053s)
 World |   Query    | QueryDatabase DELETE FROM dynamic_zones WHERE instance_id IN (101) -- (0 rows affected) (0.000025s)
 World |   Query    | QueryDatabase DELETE FROM spawn2_disabled WHERE instance_id IN (101) -- (0 rows affected) (0.000018s)
 World |   Query    | QueryDatabase DELETE FROM data_buckets WHERE instance_id != 0 and instance_id IN (101) -- (0 rows affected) (0.000026s)
 World |   Query    | QueryDatabase DELETE FROM zone_state_spawns WHERE `instance_id` IN (101) -- (82 rows affected) (0.003508s)
 World |   Query    | QueryDatabase DELETE FROM data_buckets WHERE (`expires` < 1743316091 AND `expires` > 0) -- (0 rows affected) (0.000081s)
 World |   Query    | QueryDatabase DELETE FROM character_expedition_lockouts WHERE expire_time <= NOW() -- (0 rows affected) (0.000025s)
 World |   Query    | QueryDatabase DELETE FROM character_task_timers WHERE expire_time <= NOW() -- (0 rows affected) (0.000017s)

Updating existing instance duration

sub EVENT_SAY {
    if ($text=~/instance/i) {
        my $instance_id = quest::CreateInstance("halas", 0, 60);
        $client->AssignToInstance($instance_id);
        $client->MoveZoneInstance($instance_id);
        quest::UpdateInstanceTimer($instance_id, 120);
    }
}

image

Checklist

  • I have tested my changes
  • I have performed a self-review of my code. Ensuring variables, functions and methods are named in a human-readable way, comments are added only where naming of variables, functions and methods can't give enough context.
  • I own the changes of my code and take responsibility for the potential issues that occur
  • If my changes make database schema changes, I have tested the changes on a local database (attach image). Updated version.h CURRENT_BINARY_DATABASE_VERSION to the new version. (Delete this if not applicable)

@Akkadius Akkadius merged commit 92128b9 into master Mar 30, 2025
2 checks passed
@Akkadius Akkadius deleted the akkadius/instance-list-expire-at branch March 30, 2025 19:46
This was referenced Mar 30, 2025
joligario added a commit to ProjectEQ/peqphpeditor that referenced this pull request Mar 30, 2025
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.

2 participants