Skip to content

Commit

Permalink
fix: select only latest *_models stats from table
Browse files Browse the repository at this point in the history
  • Loading branch information
tazlin committed Jun 24, 2024
1 parent bd971c2 commit 6695fe5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion horde/classes/kobold/genstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ def get_compiled_textgen_stats_models() -> dict[str, dict[str, int]]:
dict[str, dict[str, int]]: A dictionary with the model as the key and the requests as the values.
"""

latest_date = db.session.query(db.func.max(CompiledTextGenStatsModels.created)).scalar()

models: tuple[CompiledTextGenStatsModels] = (
db.session.query(CompiledTextGenStatsModels).order_by(CompiledTextGenStatsModels.created.desc()).all()
db.session.query(CompiledTextGenStatsModels).filter(CompiledTextGenStatsModels.created == latest_date).all()
)

periods = ["day", "month", "total"]
Expand Down
4 changes: 3 additions & 1 deletion horde/classes/stable/genstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ class CompiledImageGenStatsModels(db.Model):
def get_compiled_imagegen_stats_models(model_state: str = "all") -> dict[str, dict[str, dict[str, int]]]:
"""Gets the precompiled image generation statistics for the day, month, and total periods for each model."""

latest_date = db.session.query(db.func.max(CompiledImageGenStatsModels.created)).scalar()

models: tuple[CompiledImageGenStatsModels] = ()

# If model_state is "all" we get all models, if it's "known" we get only known models, if it's "custom" we get only custom models
Expand Down Expand Up @@ -245,7 +247,7 @@ def get_compiled_imagegen_stats_models(model_state: str = "all") -> dict[str, di
latest_entry = (
db.session.query(CompiledImageGenStatsModels)
.filter_by(model_name=model.model_name)
.order_by(CompiledImageGenStatsModels.created.desc())
.filter(CompiledImageGenStatsModels.created == latest_date)
.first()
)

Expand Down

0 comments on commit 6695fe5

Please sign in to comment.