Skip to content

Commit 37be1cf

Browse files
committed
Fix getChunkTimestamps query
Turns out that doing an aggregate function like MAX without having a group by, in this case, is a *bad* idea. Also I seemed to have forgotten that regions are 32x32, not 16x16 :s
1 parent 2b5a09d commit 37be1cf

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

mapsync-server/src/database.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ export async function getChunkTimestamps(
102102
regionX: number,
103103
regionZ: number,
104104
) {
105-
const minChunkX = regionX << 4,
106-
maxChunkX = minChunkX + 16;
107-
const minChunkZ = regionZ << 4,
108-
maxChunkZ = minChunkZ + 16;
105+
const minChunkX = regionX << 5,
106+
maxChunkX = minChunkX + 32;
107+
const minChunkZ = regionZ << 5,
108+
maxChunkZ = minChunkZ + 32;
109109
return get()
110110
.selectFrom("player_chunk")
111111
.select([
@@ -118,6 +118,7 @@ export async function getChunkTimestamps(
118118
.where("chunk_x", "<", maxChunkX)
119119
.where("chunk_z", ">=", minChunkZ)
120120
.where("chunk_z", "<", maxChunkZ)
121+
.groupBy(["chunk_x", "chunk_z"])
121122
.orderBy("ts", "desc")
122123
.execute();
123124
}

0 commit comments

Comments
 (0)