forked from MTSR/mapserver
postgres wip
This commit is contained in:
parent
bac0472282
commit
18fb3240d5
@ -51,9 +51,8 @@ func (this *PostgresAccessor) FindBlocksByMtime(gtmtime int64, limit int) ([]*db
|
||||
|
||||
func (this *PostgresAccessor) FindLegacyBlocksByPos(lastpos *coords.MapBlockCoords, limit int) ([]*db.Block, error) {
|
||||
blocks := make([]*db.Block, 0)
|
||||
pc := coords.CoordToPlain(lastpos)
|
||||
|
||||
rows, err := this.db.Query(getLastBlockQuery, pc, limit)
|
||||
rows, err := this.db.Query(getLastBlockQuery, lastpos.X, lastpos.Y, lastpos.Z, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -102,9 +101,7 @@ func (this *PostgresAccessor) CountBlocks(frommtime, tomtime int64) (int, error)
|
||||
|
||||
|
||||
func (this *PostgresAccessor) GetBlock(pos *coords.MapBlockCoords) (*db.Block, error) {
|
||||
ppos := coords.CoordToPlain(pos)
|
||||
|
||||
rows, err := this.db.Query(getBlockQuery, ppos)
|
||||
rows, err := this.db.Query(getBlockQuery, pos.X, pos.Y, pos.Z)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -128,6 +125,6 @@ func (this *PostgresAccessor) GetBlock(pos *coords.MapBlockCoords) (*db.Block, e
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func NewPostgresAccessor(filename string) (*PostgresAccessor, error) {
|
||||
func NewPostgresAccessor(connStr string) (*PostgresAccessor, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -1,22 +1,28 @@
|
||||
package postgres
|
||||
|
||||
const migrateScript = `
|
||||
alter table blocks add mtime integer default 0;
|
||||
create index blocks_mtime on blocks(mtime);
|
||||
alter table blocks add column mtime bigint not null default 0;
|
||||
|
||||
CREATE TRIGGER update_blocks_mtime_insert after insert on blocks for each row
|
||||
begin
|
||||
update blocks set mtime = strftime('%s', 'now') where pos = new.pos;
|
||||
end;
|
||||
create index BLOCKS_TIME on blocks(mtime);
|
||||
|
||||
CREATE TRIGGER update_blocks_mtime_update after update on blocks for each row
|
||||
begin
|
||||
update blocks set mtime = strftime('%s', 'now') where pos = old.pos;
|
||||
end;
|
||||
create or replace function on_blocks_change() returns trigger as
|
||||
$BODY$
|
||||
BEGIN
|
||||
NEW.mtime = floor(EXTRACT(EPOCH from now()) * 1000);
|
||||
return NEW;
|
||||
END;
|
||||
$BODY$
|
||||
LANGUAGE plpgsql;
|
||||
|
||||
create trigger blocks_update
|
||||
before insert or update
|
||||
on blocks
|
||||
for each row
|
||||
execute procedure on_blocks_change();
|
||||
`
|
||||
|
||||
const getBlocksByMtimeQuery = `
|
||||
select pos,data,mtime
|
||||
select posx,posy,posz,data,mtime
|
||||
from blocks b
|
||||
where b.mtime > ?
|
||||
order by b.mtime asc
|
||||
@ -24,11 +30,13 @@ limit ?
|
||||
`
|
||||
|
||||
const getLastBlockQuery = `
|
||||
select pos,data,mtime
|
||||
select posx,posy,posz,data,mtime
|
||||
from blocks b
|
||||
where b.mtime = 0
|
||||
and b.pos > ?
|
||||
order by b.pos asc, b.mtime asc
|
||||
and b.posx >= ?
|
||||
and b.posy >= ?
|
||||
and b.posz >= ?
|
||||
order by b.posx asc, b.posy asc, b.posz asc, b.mtime asc
|
||||
limit ?
|
||||
`
|
||||
|
||||
@ -38,5 +46,8 @@ select count(*) from blocks b where b.mtime >= ? and b.mtime <= ?
|
||||
|
||||
|
||||
const getBlockQuery = `
|
||||
select pos,data,mtime from blocks b where b.pos = ?
|
||||
select pos,data,mtime from blocks b
|
||||
where b.posx = ?
|
||||
and b.posy = ?
|
||||
and b.posz = ?
|
||||
`
|
||||
|
Loading…
Reference in New Issue
Block a user